in reply to Re: Improving if statements
in thread Improving if statements
my @keys = ('test', 'dark', 'white', 'house', 'all things', 'money', 'count +ry'); my @values = qw(blue black light home multi value USA); my $regex = join '|', @keys; # "map quotemeta" might be needed for ugl +ier keys $regex = qr/($regex)/; my %switch; @switch{@keys} = @values; my $change; if ($item =~ $regex) { $change = $switch{$1}; } else { $change = "neutral"; } print "Final Item = $change.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Improving if statements
by Anonymous Monk on Sep 18, 2014 at 23:55 UTC |