Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Clean perl code (unused functions)

by Errto (Vicar)
on Jun 25, 2007 at 19:27 UTC ( #623233=note: print w/ replies, xml ) Need Help??


in reply to Re: Clean perl code (unused functions)
in thread Clean perl code (unused functions)

Not exactly related to the OP, but I am wondering: how does that code pass strict? Isn't it effectively using symbolic references, ie. generating a method name from a string?


Comment on Re^2: Clean perl code (unused functions)
Re^3: Clean perl code (unused functions)
by GrandFather (Cardinal) on Jun 25, 2007 at 22:08 UTC

    I've trawled through much of the Perl documentation looking for something that addresses exactly that issue and can't find anything. Pretty much all of the pertinent examples use scalar variables rather than member functions.

    It is however a very useful technique to dispatch to members in the context of a parser. Decorate the verb to avoid the possibility of nefarious calling of unintended members (DESTROY in the document being parsed could otherwise be a little unfortunate) and you've got a very easily extensible interpreter for all sorts of stuff (see sub describeAtom in Updated QuickTime format movie file dumper for example).

    It's probably better to use the function reference returned from can (see 'UNIVERSAL: The Root of All Objects' in perltoot) though (amazing what you learn by re-reading the docs;) ):

    for (@mem) { next unless my $member = $obj->can ("_do_$_"); $obj->$member (); }

    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://623233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-08-01 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls