Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: execute function with name passed as string parameter

by Utilitarian (Vicar)
on May 05, 2011 at 10:09 UTC ( [id://903108]=note: print w/replies, xml ) Need Help??


in reply to execute function with name passed as string parameter

You are not assigning a code_ref in your hash, but rather the out put of your routines, this causes them to run on assignment.
perl -e '$choice="1"; %hash=( 0 => one, 1 => two ); sub one {print "on +e\n"}; sub two {print "two\n"} &{$hash{$choice}}' two
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://903108]
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: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found