in reply to Re: Check if at least one element of array is bigger than X
in thread Check if at least one element of array is bigger than X

<O>so the test is really "are there any elements who's value is > 10?"

Maybe logically, but it still checks the entire list.

  • Comment on Re^2: Check if at least one element of array is bigger than X

Replies are listed 'Best First'.
Re^3: Check if at least one element of array is bigger than X
by GrandFather (Saint) on Apr 08, 2010 at 01:36 UTC
    but it still checks the entire list

    So what? Maybe that is an issue if the list is tens of thousands of items long and the test is being performed often, but in most cases neither criteria is met and the simplistic grep solution is by far the simplest and most maintainable technique. For the vast majority of cases avoiding grep for efficiency reasons is a perfect example of why we implore people to avoid premature optimisation.

    When I was writing my original reply I considered opening that particular can of worms, but given the nature of the OP's question decided that the additional layer of confusion wasn't warranted - sigh.

    True laziness is hard work
      So what?

      Its a caveat you omitted.

        The entire list is visited with the any and the first solutions too (although the check function is only called until a match is found). for (@a) is saved due to the an optimisation that prevents the flattening of the list if it consists of just an array.

        Update: Added reference to newly added first solution.