develooper Front page | perl.perl5.porters | Postings from July 2009

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

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
July 24, 2009 09:50
Subject:
Re: [perl #67694] List::Util attaching to the wrong $_ when usedinside given/when construct
Message ID:
20090724165039.GR4204@iabyn.com
On Tue, Jul 21, 2009 at 12:45:04PM +0200, Rafael Garcia-Suarez wrote:
> Ah, you're right. The parser has this line :
> switch  :       label GIVEN '(' remember mydefsv mexpr ')' mblock
> where mydefsv is an empty rule that lexicalizes $_.
> But then the code I pasted above could probably be simplified.


So if I've understood this correctly, given() adds a lexical $_ to the
scope, and there's a bug in List::Util::first in that it doesn't work with
a lexical $_? So not a bug in given/smartmatch?

    use List::Util  qw/first/;
    print "ok outside\n" if first { $_ } 1;
    {
	my $_ = 0;
	print "ok inside\n" if first { $_ } 1;
    }

outputs:

    ok outside


-- 
Technology is dominated by two types of people: those who understand what
they do not manage, and those who manage what they do not understand. 

Thread Previous | Thread Next


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