Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Strict, strings and subroutines

by davorg (Chancellor)
on Oct 10, 2001 at 16:18 UTC ( #117978=note: print w/ replies, xml ) Need Help??


in reply to Strict, strings and subroutines

I'd do this by creating a hash of references to the various subroutines like this:

sub do_x { print "processing x\n"; } sub do_y { print "processing y\n"; } my %subs = ( x => \&do_x, y => \&do_y );

Then when you know what type you're going to be processing, you can do something like this:

$subs{$type}->();
--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


Comment on Re: Strict, strings and subroutines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-12-25 00:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls