Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-08-21 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (142 votes), past polls