http://www.perlmonks.org?node_id=1166690


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,