Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re^2: Lexical pad / attribute confusion

by shotgunefx (Parson)
on Dec 22, 2002 at 00:00 UTC ( [id://221688]=note: print w/replies, xml ) Need Help??


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

Because they are declared after dump_lex.

-Lee

"To be civilized is to deny one's nature."
  • Comment on Re: Re^2: Lexical pad / attribute confusion

Replies are listed 'Best First'.
Re^4: Lexical pad / attribute confusion
by adrianh (Chancellor) on Dec 22, 2002 at 00:08 UTC

    They're also declared after INIT, and you can see them from there ;-) Also, moving dump_lex after the declarations like this:

    Still gives you this (under 5.8):

    when init top-level pad is HASH(0x22e150) -> $%bar = \{}; HASH(0xb5b50) -> $%foo = \{}; when setting Attr in Foo for HASH(0xb5b50) top-level pad is when setting Attr in Bar for HASH(0x22e150) top-level pad is HASH(0x22e150) -> $%bar = \{}; when runtime top-level pad is
      Actually I get different results. On 5.6.1 (win32) lexicals declared after INIT are not visible from INIT.
      #!/usr/bin/perl use warnings; use strict; INIT { use Data::Dumper; use PadWalker qw (peek_my peek_sub); print Dumper(peek_my(0)); } my $foo = 'lee'; my $bar = "Bar"; { my @foo = (1..3); } { my @bar = (9..12); } print Dumper(peek_my(0)) __END___ $VAR1 = {}; $VAR1 = { '$foo '$bar };
      my has both runtime and compile time effects, I wouldn't be suprised if they are on the same pad, but are removed from the padlist when the block is exited.

      -Lee

      "To be civilized is to deny one's nature."
        Actually I get different results. On 5.6.1 (win32) lexicals declared after INIT are not visible from INIT.

        My results on 5.8 match yours if I run your code. Not surprising since your code is different from mine :-)

        dump_lex climbs up the callstack to the enclosing file lexical scope. So it would be the same sort of thing as doing this:

        use warnings; use strict; INIT { use Data::Dumper; use PadWalker qw (peek_my peek_sub); print Dumper(peek_my(1)); } my $foo = 'lee'; my $bar = "Bar"; print Dumper(peek_my(0)); { my @foo = (1..3) }; { my @bar = (9..12) }; print Dumper(peek_my(0));

        Which gives (on 5.8)

        $VAR1 = { '$foo' => \undef, '@bar' => [], '@foo' => [], '$bar' => \undef }; $VAR1 = { '$foo' => \'lee', '$bar' => \'Bar' }; $VAR1 = { '$foo' => \'lee', '$bar' => \'Bar' };

        Again, INIT can see everything, but nothing can be seen before/after the blocks are executed at the top level. I still don't understand what's happening here :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found