Subject: | Using "first" within a block for "first" causes a strange return value |
In the attached test, @l is ( [qw/a b c/], [qw/d e f/] ). The way I
read the docs, first BLOCK @l should return either [qw/a b c/], [qw/d e
f/], or undef, regardless of what BLOCK is.
If I call first BLOCK @l from a list context, I can make it return [undef].
One could call this a bug in the implementation or in the documentation:
"don't do that!" is probably a reasonable response to
first { first { ... } @$_ } @l ;
Subject: | list_first_bug.t |
#!/usr/bin/perl
use strict ;
use warnings ;
use Data::Dumper ;
use Test::More tests => 7 ;
use List::Util ;
my @l = ( [qw/a b c/], [qw/d e f/] ) ;
my @s = List::Util::first { List::Util::first { $_ eq 'e' } @$_ } @l ;
ok( @s, 'e is found' ) ;
ok( $s[0], 'e is really found' ) ;
is( ref $s[0], 'ARRAY', 'e is in an ARRAYREF' ) ;
my @t = List::Util::first { List::Util::first { $_ eq 'z' } @$_ } @l ;
ok( ! @t, 'z is not found' )
|| warn Dumper( \@t );
ok( ! $t[0], 'z is really not found' ) ;
ok( ! ref $t[0], 'z is really, really not found' ) ;
my $tSca = List::Util::first { List::Util::first { $_ eq 'z' } @$_ } @l ;
ok( ! $tSca, 'z is not found in scalar' ) ;