http://www.perlmonks.org?node_id=1067538


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)