Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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);


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://813193]
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: (4)
As of 2016-10-25 15:09 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (322 votes). Check out past polls.