develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #67694] List::Util attaching to the wrong $_ when used inside given/when construct

Thread Previous
From:
Father Chrysostomos via RT
Date:
December 10, 2011 11:53
Subject:
[perl #67694] List::Util attaching to the wrong $_ when used inside given/when construct
Message ID:
rt-3.6.HEAD-5084-1323546817-1628.67694-14-0@perl.org
On Sat Dec 10 11:51:52 2011, sprout wrote:
> On Sat Dec 10 09:55:36 2011, fany@cpan.org wrote:
> > 
> > This is a bug report for perl from fany@cpan.org,
> > generated with the help of perlbug 1.39 running under perl 5.14.2.
> > 
> > 
> > -----------------------------------------------------------------
> > [Please describe your issue here]
> > 
> > 
> > When I use a function which expects a codeblock as first
> > argument, like List::Util::first(), within a "given" block,
> > then $_ within that codeblock does not work properly, but
> > keeps the value of the $_ from the "given" block.
> > 
> > Or, in other words, the test script below will output the
> > following:
> > 
> > 	1 - 2 - 3 - grep OK!
> > 	1 - first OK!
> > 	1 - fpp OK!
> > 	1 - 2 - 3 - grep within given OK!
> > 	0 - 0 - 0 -
> > 	0 - 0 - 0 -
> > 
> > Kind regards,
> > fany
> 
> This is a known issue, #67694.  given does an implicit ‘my $_’.  See
> also ticket #90018 and ticket #53186 (marked as resolved, even though it
> isn’t).

BTW, the easiest workaround is to use ‘for’ instead of ‘given’.  You can
still use ‘when’ inside ‘for’.

-- 

Father Chrysostomos


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About