develooper Front page | perl.perl5.porters | Postings from July 2012

Re: [perl #113974] package NAMESPACE manpage comments

Thread Previous | Thread Next
From:
Eric Brine
Date:
July 6, 2012 08:19
Subject:
Re: [perl #113974] package NAMESPACE manpage comments
Message ID:
CALJW-qF_SDryf3gByrp19DL8sjPk_O3jcNODcmGCrxocpYwyow@mail.gmail.com
On Fri, Jul 6, 2012 at 4:30 AM, Linda W <perl-diddler@tlinx.org> wrote:

>  'my' has dynamic scope


No, it does not. Contrast with local which provides dynamic scoping:

>perl -E"sub f { say $x } { my $x = 123; f() }"

>perl -E"sub f { say $x } { local $x = 123; f() }"
123



> in the it goes away at end of the physical boundaries (sans any references
> to it).
>

Yes, that's called lexical scoping. or static scoping. Did you follow the
link I gave?


> It also dynamically is created when you enter the physical boundaries of
> it's lexical scope.


Scope has nothing to do with where are variable is created. Scope is
entirely about where it's visible.

You're also completely wrong about where and when it's created. A "my"
variable is created at run-tine, and either cleared or recreated on scope
*exit*.


> It's a new var at that point.
>

Yes,


> Such isn't true with state or our.
>

Not so. Equally new var there. A variable is an association between a name
and an address. "state", "our", and "my" equally create variables.

You seem to be confusing "scope" with "allocation".

- Eric

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