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

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

by perlfan (Vicar)
on Jun 27, 2016 at 19:40 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-24 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found