Skip to content

Instantly share code, notes, and snippets.

@koorchik
Created June 2, 2012 11:26
Show Gist options
  • Select an option

  • Save koorchik/2857889 to your computer and use it in GitHub Desktop.

Select an option

Save koorchik/2857889 to your computer and use it in GitHub Desktop.
List::Util::first bug
use List::Util qw/first/;
use List::MoreUtils qw/first_value/;
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' );
is( test('list_more_utils'), 4, 'List::MoreUtils::first_value 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 ('list_more_utils') {
my $first = first_value { $_ == 4 } @array;
return $first;
}
when ('grep') {
my ($first) = grep { $_ == 4 } @array;
return $first
}
default {
die "wrong test";
}
}
}
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment