develooper Front page | perl.perl5.porters | Postings from November 2014

Re: [perl #123322] "our" has the same scoping rules as "my" or "state"

Thread Previous | Thread Next
From:
Eric Brine
Date:
November 29, 2014 22:51
Subject:
Re: [perl #123322] "our" has the same scoping rules as "my" or "state"
Message ID:
CALJW-qG2_-fFL+LXkj=QgVXHKVD=e0+KOe8KWwDOAw6=nGPJXg@mail.gmail.com
On Fri, Nov 28, 2014 at 11:32 PM, Father Chrysostomos via RT <
perlbug-followup@perl.org> wrote:

> On Fri Nov 28 15:34:12 2014, ikegami@adaelis.com wrote:
> >
> > This is a bug report for perl from ikegami@adaelis.com,
> > generated with the help of perlbug 1.40 running under perl 5.20.1.
> >
> >
> > -----------------------------------------------------------------
> > [Please describe your issue here]
> >
> >
> > $ perldoc -f our | grep 'same scoping'
> >             "our" has the same scoping rules as "my" or "state",
> > meaning that
> >
> > $ perl -Mstrict -E'say( ( our $y = "abc" ), $y )'
> > abcabc
> >
> > $ perl -Mstrict -E'say( ( my $y = "abc" ), $y )'
> > Global symbol "$y" requires explicit package name at -e line 1.
> > Execution of -e aborted due to compilation errors.
> >
> > Seems the docs aren't accurate.
>
> There is code in pad.c to make ‘our’ cover the current statement (if there
> are no pad entries already under the same name in scope from previous
> statements), added in 929a0744021. The relevant thread starts at <
> FC2E47BE-B781-11D7-BE4D-000A95A2734C@nanisky.com>.
>

So sometimes "our" is scoped like "my", and sometimes it isn't? ow!

$ perl -E'use strict; $::x = "pkg";                say our $x, $x'
pkgpkg

$ perl -E'use strict; $::x = "pkg"; my $x = "lex"; say our $x, $x'
pkglex

I just said the docs weren't accurate, but now you tell me the behaviour is
wacky too. The linked thread explains that introducing the wackiness was
necessary because it was a maintenance release. But that's done. I just
mentioned the docs were inaccurate, but some consistency (one way or
another) would be nice.

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