develooper Front page | perl.perl5.porters | Postings from February 2013

Re: Salvaging lexical $_ from deprecation

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
February 24, 2013 00:47
Subject:
Re: Salvaging lexical $_ from deprecation
Message ID:
20130224004744.GW2294@iabyn.com
On Tue, Feb 19, 2013 at 10:53:41PM +0100, Rafael Garcia-Suarez wrote:
> On 19 February 2013 22:41, Jesse Luehrs <doy@tozt.net> wrote:
> > On Tue, Feb 19, 2013 at 10:37:31PM +0100, Rafael Garcia-Suarez wrote:
 >
> > This is still exactly dynamic scoping, as far as I can see. Compare:
> >
> >   $ perl -E'sub foo { say $::foo } local $::foo = "f"; foo'
> >   f
> >
> >   $ perl -E'sub foo { say $::foo || "nothing" } { local $::foo = "f" } foo'
> >   nothing
> 
> I stand corrected. (Pretty sure the internals don't do a full
> localisation though :)

It's the "current successfully matched RE" (PL_curpm) which is localised
and updated on each scope exit; $1 et al just act like tied vars (well,
magic actually) that retrieve a string from the current pattern match -
which includes (possibly a copy of) the original string plus capture index
pairs.

-- 
Hofstadter's Law: It always takes longer than you expect, even when you
take into account Hofstadter's Law.

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