Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^6: Smartmatch alternatives

by LanX (Canon)
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.

update

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-07-07 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls