Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^6: Smartmatch alternatives

by LanX (Chancellor)
on Dec 17, 2013 at 22:08 UTC ( #1067538=note: print w/replies, xml ) Need Help??

in reply to Re^5: Smartmatch alternatives
in thread Smartmatch alternatives

Thanks, but this can't be fixed.

The problem is that the design of List::Util first is broken, no result should be an empty list and not undef! At least in list context ! :(

DB<28> \@x => [1, 2, 3, undef, 5, 6, 7, 8, 9, 10] DB<29> @a=List::Util::first { !$_ } @x; \@a => [undef] DB<30> @a=List::Util::first { $_ eq "never" } @x; \@a => [undef]

I wished people would learn the lesson that () is always better then undef for failure in list operations like iterators or filters.


grep does it right!

DB<38> @a=grep { !$_ } @x; \@a => [undef] DB<39> @a=grep { $_ eq "never" } @x; \@a => []

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067538]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-07-22 17:20 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (340 votes). Check out past polls.