XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I've seen List:Util::first mentioned a couple of times, and agree that will work fine. I recommend List::MoreUtils::any, however, as its meaning and intent is clearer since it has a name that matches the problem. (++) though I'd like to put it stronger: although it doesn't make a difference in this particular case, List::MoreUtils::any is the only one that will work in general even when the value to search does not evaluate to boolean true. This will not work: print "@a\n" if List::Util::first { 0 == $_ } @aThis will: print "@a\n" if List::MoreUtils::any { 0 == $_ } @aIf it wasn't for the difference that any returns a boolean "found" while first returns the actual element found, the two might as well be aliases to the same code. grep in scalar context will work fine too but if the list is large it may be wasteful because it always goes through the whole list to return the number of matches even if it could stop after the first. In reply to Re^2: If any element-in-array comparision
by mbethke
|
|