![]() |
|
Perl: the Markov chain saw | |
PerlMonks |
Shortcutting grep in boolean contextby perlancar (Hermit) |
on Jan 03, 2017 at 20:27 UTC ( #1178871=perlquestion: print w/replies, xml ) | Need Help?? |
perlancar has asked for the wisdom of the Perl Monks concerning the following question: If grep were to be made shortcutting in boolean/scalar context (returning only the first result, or returning just true/false), would it break many programs? I would prefer a shortcutting grep, making it behave like List::Util's first but faster for larger lists. Also, what do you guys think of this idiom to simulate shortcutting of grep: if (eval { grep {$_==$wanted and die} @ary}, @$) { say "match" } Also, how about shortcutting map() too in boolean context? Although that makes less sense.
Back to
Seekers of Perl Wisdom
|
|