in reply to Re: if ... elsif ... else
in thread if ... elsif ... else

Please note that  any() all() none() etc. are not found in early versions of List::Util. These functions were introduced first in List::MoreUtils and later included in the former module — but they're still present in the latter.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: if ... elsif ... else
by Eily (Monsignor) on Jun 01, 2017 at 16:11 UTC

    I did think about checking if they where present in List::Util or not, but didn't think about previous versions. ++ for the precision.

    Anyway, this is a case where any() can be replaced by grep to obtain the same result. So say $i unless grep { $i % $_ } (2,3,5);

      ... any() can be replaced by grep to obtain the same result.

      Insofar as the final result is concerned, I'd agree. The only caveat I'd offer is that for sufficiently large sets of prime factors 2, 3, 5, ..., or of ranges of numbers to be checked, use of a short-circuiting function like  any() or  none() may offer a noticable performance advantage over grep, which will always process every item in its input list. Of course, this can only be finally determined by benchmarking of some kind.


      Give a man a fish:  <%-{-{-{-<