Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://738837]
help
Chatterbox?
[james28909]: yep, i am scraping a websites date/time stamp from an article. none of that is relevant though because the strings i get are as expected. the returned data from the website is the list of @weekdays
[james28909]: i need to convert those @weekdays to an numerical date based off of scalar localtime
[james28909]: i have thught about this and though about it lol

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2017-04-29 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.