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

Re: Salvaging lexical $_ from deprecation

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
February 19, 2013 22:24
Subject:
Re: Salvaging lexical $_ from deprecation
Message ID:
CAHAeAG4T+XFnMxtsuJVhFZ-uAt8yryZYBvHOqwHrn4SLOqvLsQ@mail.gmail.com
On Tue, Feb 19, 2013 at 10:37 PM, Rafael Garcia-Suarez <rgs@consttype.org>wrote:

> No, it's not dynamic scoping: (I specified "for a definition of
> scope..." because I'm aware of the weird lexical scoping rules applied
> there)
>
> ~ยง perl -E'sub foo { say $1 || "nothing" } { "foo" =~ /(.)/ } foo'
> nothing
>

  That's outside of the dynamic scope, so as should be expected.  Compare:

~$ perl -E'sub foo { say $1 || "nothing" } { "foo" =~ /(.)/; foo }'
f

  This time the $1 is inside the dynamic scope of the bare block (and so
see the localized $1), but outside of the lexical scope (and so could not
have seen that $1, if it were lexically scoped).


Eirik

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