Gunnar Hjalmarsson said:
Quote from the applicable Perl FAQ ("perldoc -q contained"):
"Please do not use
($is_there) = grep $_ eq $whatever, @array;
or worse yet
($is_there) = grep /$whatever/, @array;
These are slow (checks every element even if the first matches),
inefficient (same reason),
Why not just say "Don't use Perl, it is slow and inefficient."?
If one doesn't care enough about efficiency to use a hash, then I highly
doubt one will care about the (generally trivial) additional inefficiency
of using grep. I've probably spent more of my time typing this reply than
all of the time wasted via grep-in-boolean-context of all the perl programs
I've ever run.
and potentially buggy (what if there are
regex characters in $whatever?)."
Both forms (the grep and the foreach loop) require you to make the correct
decision regarding use of eq versus =~ versus ==. If you habitually use
regex when you shouldn't be, then the suggested replacement is just as
"potentially buggy" as what it is replacing.
Xho