Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to call sub defined in a variable?

by revdiablo (Prior)
on Jan 25, 2009 at 22:46 UTC ( #738837=note: print w/ replies, xml ) Need Help??


in reply to How to call sub defined in a variable?

Another way to do it. Put your code references in a hash, otherwise known as a dispatch table:

# Pick a more descriptive name for this hash, depending on your need my %subroutines = ( test => \&test, another_test => \&another_test, third_test => \&third_test, ); for (qw(test another_test third_test)) { $subroutines{$_}->(); }

This lets you define exactly which routines you can call using this method, rather than opening up everything and anything in the main namespace.


Comment on Re: How to call sub defined in a variable?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2015-07-03 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls