in reply to Re: if,if and again,if
in thread if,if and again,if
Data-driven approaches FTW!
Though I'd be tempted to do things a bit more perlishly (at least for my own definition of perlish):
Actually, a bit more perlish, IMO, would be to replace that for loop altogether:my @matchers = ( [ qr/(Lz0|PLATO)/i => 'Apps' ], ... ); for my $check (@matchers) { if ($release_name =~ $check->[0]) { $category = $check->[1]; print "[INFO] Category: $category\n"; last; } }
But maybe that's just me. :-)use List::Util qw(first); my $category = map { $_ ? $_->[1] : undef; } first { $release_name =~ $_->[0]; } @matchers; if ($category) { print "[INFO] Category: $category\n"; } else { print "[ERROR] Unrecognised release type: $release_name\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: if,if and again,if
by moritz (Cardinal) on Aug 23, 2012 at 18:04 UTC |