Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: If any element-in-array comparision

by repellent (Priest)
on Jan 29, 2012 at 22:39 UTC ( #950669=note: print w/replies, xml ) Need Help??

in reply to Re^2: If any element-in-array comparision
in thread If any element-in-array comparision

    This will not work:

    print "@a\n" if List::Util::first { 0 == $_ } @a

When using first as a condition, it's best to wrap it in a defined() to specifically check for the 'not found' case:
# this always works print "@a\n" if defined(List::Util::first { defined($_) && 0 == $_ } @ +a);

OTOH, I agree that first clobbers the predicate when checking for undef -- i.e. we can't tell if we found undef:
# doesn't work print "@a\n" if defined(List::Util::first { !defined($_) } @a);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950669]
[james28909]: just to get around not being able to do yt-dl | ffmpeg
[james28909]: learning is fun ISNT IT?!?!!??
[RonW]: that seems very weird to me
choroba submitted 2 talks to (YA|T)PC::EU
[RonW]: Choroba: I hope they get accepted
[marioroy]: ++ choroba
[1nickt]: Topics, choroba?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2017-05-22 21:23 GMT
Find Nodes?
    Voting Booth?