in reply to matching strings...
Why not use a list operator in this case? grep comes to mind, but especially first that is in the List::Util module (part of the Perl 5.8 distribution if memory serves).
use List::Util qw( first ); if (defined(first {'abc' eq $_} qw( abc def ghi ))) { print "found 'abc'\n"; }
Hope this helps, -gjb-
Update: Thanks to diotalevi for pointing out issues with my solution. I agree with both: I suggested first for exactly his objection to grep and I modified the original code by adding defined to resolve his objection to find.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: matching strings...
by diotalevi (Canon) on Jan 27, 2003 at 08:32 UTC |