in reply to Re: Common Perl Idioms
in thread Common Perl Idioms

I would have said !!grep, not 0+grep. 0+ will return 0 or 1. !! will return canonical true or false.

Replies are listed 'Best First'.
Re^3: Common Perl Idioms
by demerphq (Chancellor) on Jul 23, 2004 at 20:09 UTC

    Well I'm not so sure how important that is, especially as it loses useful and already obtained information (ie the count). Also for the canonical return isn't 0 < grep better? It would also return the canonical true/false but is only a single operator...


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      Ah, but !! is an idiom, and more readily recognizable to my eyes. With 0< it takes me a second to figure out what the code is trying to compare. In any case, 0 < has to load a constant then do a compare, so it's still two ops.