in reply to Sparing multiple 'or's
Personally, I'd use a hash:
my %expr = ( EX_CASE1 => { map { $_ => 1 } qw( ABA SCO ACC PHC GHF ) }, EX_CASE2 => {}, # … ); : : if (exists $expr{EX_CASE1}{$a}) { ... } : if (exists $expr{EX_CASE2}{$b}) { ... }
but I'd choose more expressive names than EX_CASE1 etc :)
You can also use List::Util's any, but that might read fine, but is very hard to optimize, so it will probably be slower the your current code
use List::Util qw( any ); if (any { $a eq $_ } qw( ABA SCO ACC PHC GHF )) { .... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sparing multiple 'or's
by Eily (Monsignor) on Jun 04, 2018 at 15:36 UTC | |
by Tux (Canon) on Jun 04, 2018 at 19:23 UTC | |
by Eily (Monsignor) on Jun 05, 2018 at 08:55 UTC |