Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Lexical pad / attribute confusion

by djantzen (Priest)
on Dec 22, 2002 at 01:37 UTC ( [id://221701]=note: print w/replies, xml ) Need Help??


in reply to Re: Lexical pad / attribute confusion
in thread Lexical pad / attribute confusion

It's worth noting as well that CHECK and END blocks give the same results as we see in INIT. So in some way those portions of a program's lifespan are privileged. Also, whether the variables have attributes is incidental to whether peek_my can see them at runtime, for example,

{ package Baz; my %baz; }

likewise only shows up when dump_lex is called from the special execution blocks.

Now, a standalone my %quux is visible no matter where dump_lex is called from. This makes me think that perhaps there is loophole in PadWalker, and that there is still a way to keep your lexicals private; namely, by relying on perl's runtime enforcement of scope which I guess is just the same mechanism that makes it possible to write:

sub foo { my $foo; { my $foo; } }

That is to say, at runtime perl knows to differentiate the two $foos based upon where they are declared, despite being written on the same pad.

Update: Duh. This isn't a loophole, but rather the documented, intended behavior. From the docs: It will only show those variables which are in scope at the point of the call. I must have read that line 10 times and it only made sense when I was about to step in the shower :)

Replies are listed 'Best First'.
Re^3: Lexical pad / attribute confusion
by diotalevi (Canon) on Dec 22, 2002 at 02:37 UTC

    Yes, that part is just stuck into the opcode tree. This turns padsv calls from references to $foo into "the scalar located at location 'blah' in the pad". This is very clear if you start peeking at your code with B::Concise.


    Fun Fun Fun in the Fluffy Chair

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://221701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found