Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Initializing a subroutine with the value of a variable

by holli (Monsignor)
on Dec 17, 2009 at 15:10 UTC ( #813193=note: print w/ replies, xml ) Need Help??


in reply to Initializing a subroutine with the value of a variable

sub foo { print 'bar' } $var = 'foo'; main->$var;
However, this calls "foo" as a class method, so the sub gets the classname as the first argument. If you dont want that, use a dispatch table.
%subs = ( 'foo' => \&foo, 'bar' => \&bar, # etc ); print $subs{$var}->($arg1, $arg2);


holli

You can lead your users to water, but alas, you cannot drown them.


Comment on Re: Initializing a subroutine with the value of a variable
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-07-28 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (186 votes), past polls