Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 77596
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: KOORCHIK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: List::MoreUtils::first_value does not localize $_ in given/when statement
See attached file with the test
Subject: list_util_bug.pl
use List::MoreUtils qw/first_value/; use v5.10; use Test::More; is( test('grep'), 4, 'Grep 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_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;
On Sat Jun 02 07:45:09 2012, KOORCHIK wrote: Show quoted text
> See attached file with the test
This is more a problem with ‘given’ than with the module. if you use $'_ or ‘our $_’ inside the block, it will work.
Суб Июн 02 13:56:26 2012, SPROUT писал: Show quoted text
> On Sat Jun 02 07:45:09 2012, KOORCHIK wrote:
> > See attached file with the test
> > This is more a problem with ‘given’ than with the module. if you use > $'_ or ‘our $_’ inside the > block, it will work.
Thank you. I just replaced "given" with "for" which does not create lexical "$_" and works correctly. for ($var) { when ("value") { } default { } }
I mark this request as closed, becaus it seems to be solved.