Re: Scoping of $/

0 views
Skip to first unread message

Luke Palmer

unread,
May 10, 2005, 8:20:44 AM5/10/05
to Ingo Blechschmidt, perl6-l...@perl.org
On 5/10/05, Ingo Blechschmidt <ibl...@web.de> wrote:
> Hi,
>
> sub foo() {
> "abc" ~~ /^(.)/; # $1 now "a"
> }
>
> sub bar() {
> "def" ~~ /^(.)/; # $1 now "d"
> foo();
> say $1; # Outputs "d"
> }
>
> bar();
>
> # Correct (I hope so)?

Yeah, they're lexical, just like in Perl 5.

Luke

Ingo Blechschmidt

unread,
May 10, 2005, 8:02:33 AM5/10/05
to perl6-l...@perl.org
Hi,

sub foo() {
"abc" ~~ /^(.)/; # $1 now "a"
}

sub bar() {
"def" ~~ /^(.)/; # $1 now "d"
foo();
say $1; # Outputs "d"
}

bar();

# Correct (I hope so)?


--Ingo

--
Linux, the choice of a GNU | Row, row, row your bits, gently down the
generation on a dual AMD | stream...
Athlon! |

Rick Delaney

unread,
May 10, 2005, 5:24:30 PM5/10/05
to Luke Palmer, Ingo Blechschmidt, perl6-l...@perl.org
On Tue, May 10, 2005 at 06:20:44AM -0600, Luke Palmer wrote:
> On 5/10/05, Ingo Blechschmidt <ibl...@web.de> wrote:
> > Hi,
> >
> > sub foo() {

say $1; # undef?

> > "abc" ~~ /^(.)/; # $1 now "a"
> > }
> >
> > sub bar() {
> > "def" ~~ /^(.)/; # $1 now "d"
> > foo();
> > say $1; # Outputs "d"
> > }
> >
> > bar();
> >
> > # Correct (I hope so)?
>
> Yeah, they're lexical, just like in Perl 5.

Not just like Perl 5, I hope. If it was then the above would print
"d".

--
Rick Delaney
ri...@bort.ca

Larry Wall

unread,
May 10, 2005, 7:51:17 PM5/10/05
to perl6-l...@perl.org
On Tue, May 10, 2005 at 05:24:30PM -0400, Rick Delaney wrote:
: On Tue, May 10, 2005 at 06:20:44AM -0600, Luke Palmer wrote:
: > Yeah, they're lexical, just like in Perl 5.

:
: Not just like Perl 5, I hope. If it was then the above would print
: "d".

Yes, Perl 5 actually uses an autolocalizing form of dynamic scoping
for the current successful match, but *only* if there was a successful
match. We're intentionally breaking that.

Larry

Reply all
Reply to author
Forward
0 new messages