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 30, 2014 01:15
Subject:
Re: [perl #123322] "our" has the same scoping rules as "my" or "state"
Message ID:
CALJW-qHBPOcjeczfLbhopE8kGJhJX1cT13kwtbFqiTL5+scyew@mail.gmail.com
On Sat, Nov 29, 2014 at 7:14 PM, Father Chrysostomos via RT <
perlbug-followup@perl.org> wrote:

> > 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.
>
> A doc patch would be nice. :-)  (I would say ‘patches welcome’, but I have
> never seen a patch welcome anyone.)
>

Changing the docs isn't going to bring consistency.

But if we want to document the current behaviour, how does the following
sound?

Like "my" and "state", "our" is only visible within a lexical scope. Unlike
"my" and "state", which both declare new (lexical) variables, "our" only
creates an alias to an existing variable: a package variable of the same
name.

When the alias becomes available depends on whether an existing "my",
"state" or "our" with the same name exists in the current scope. If one
does, the alias becomes available at the beginning of the next statement.
Otherwise, it becomes available immediately.

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