http://qs321.pair.com?node_id=240055


in reply to Re: Flag variables
in thread Flag variables

Though it is always good to use built-ins like "grep" whenever possible, in this case there is a difference between this code and the original: In the original, once the test succeeds, it is no longer performed (i.e. last is called), whereas here the test will be performed on every item in the list. If this is a simple equality test, that is not so bad, but if it is something like a database lookup, and the list is long, that is a lot of extra overhead.

Now if grep were smart enough to shortcut when called in "boolean" context, then there would be no reason not to use it. Of course, "boolean" context per se won't exist until perl 6...

--JAS

Replies are listed 'Best First'.
Re^3: Flag variables
by adrianh (Chancellor) on Mar 07, 2003 at 11:05 UTC
    Now if grep were smart enough to shortcut when called in "boolean" context, then there would be no reason not to use it. Of course, "boolean" context per se won't exist until perl 6...

    Until then, using first from List::Util is one alternative.