Possible Duplicate:
How do I implement dispatch tables in Perl?
I have a hash table that contains commands such as int(rand()) etc.
How do I execute those commands?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
eval($str)to execute Perl code you store in a string variable,$str. You could alternatively store your code as function references within a hash, so something like:This way, you could write
$hash{'random'}->()to execute the function whenever you want a random value.See also Implementing Dispatch Tables on PerlMonks.