Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Initializing a subroutine with the value of a variable

by holli (Abbot)
on Dec 17, 2009 at 15:10 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found