Subject: | List::Util::first does not localize $_ in given/when statement |
See attached file with test
Subject: | list_util_bug.pl |
use List::Util qw/first/;
use v5.10;
use Test::More;
is( test('grep'), 4, 'Grep for finding first value' );
is( test('list util'), 4, 'List::Util::first for finding first value' );
sub test {
my $mode = shift;
my @array = (1..10);
given ($mode) {
when ('list_util') {
my $first = first { $_ == 4 } @array;
return $first;
} when ('grep') {
my ($first) = grep { $_ == 4 } @array;
return $first
}
}
}
done_testing;