Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Best option for "switch/case" functionality?

by perlfan (Priest)
on Jun 27, 2016 at 19:40 UTC ( #1166690=note: print w/replies, xml ) Need Help??


in reply to Best option for "switch/case" functionality?

If your cases don't need to be evaluated conditionally, I like to use a hashref:
my $dispatch = { option1 => sub { print "opt 1\n"}, option2 => sub { print "opt 2\n"}, option3 => sub { print "opt 3\n"}, default => sub { print "default\n" }, }; $dispatch->{($dispatch->{$option})?$option:'default'}->(@args);
YMMV,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2020-06-03 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (22 votes). Check out past polls.

    Notices?