I'd go with a lookup-table. Since you can look up directly in a hash table, a list will have to do...
my @keys = ( [ "key1" => sub { handle_key1 } ], # inline anony sub [ "key2" => \&handle_key2 ], # use a named function [ "key3" => sub { ... } ], # ... ); use List::Util qw(first); # find the entry my $data = first { index($mystring, $_->[0]) >= 0 } @keys; # call the code $data->[1]->();
In reply to Re: if or switch?
by Tanktalus
in thread if or switch?
by gw1500se
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |