Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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)

Comment on Re^6: Smartmatch alternatives
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067538]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-11-27 13:09 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (729 votes), past polls