Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Perl Internals - references and symbol table

by shotgunefx (Parson)
on Nov 16, 2002 at 08:11 UTC ( [id://213376]=note: print w/replies, xml ) Need Help??


in reply to Perl Internals - references and symbol table

Paraphrasing.. but the gist is lexicals are stored in scratchpads which is basically an AoA. Scratchpads are assoiciated with { scopes }

The first element is an array of the lexical names in that pad
The second element is an array of the values
If the subroutine recurses, it populates subsequent elements with new values so each sub has it's own set of lexical values. Because most of this is known at compile time, I believe perl usually optimizes the names away and goes directly to the lexicals's index instead of searching through the pads lexicals names for the index. Of course perlguts has a much more gory (and correct) description of the workings.

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Perl Internals - references and symbol table
by Elian (Parson) on Nov 16, 2002 at 19:30 UTC
    Scratchpads are assoiciated with { scopes }
    Not quite. Scratchpads are associated with subs, not with blocks. Yes, from a language level it looks like there's a scratchpad per block, but under the hood there really isn't.
      Thanks Elian, I'm trying to improve me understanding of internals (Just got Embedding and Extending Perl). In the following example where do the lexicals for the bare block live then?
      #!/usr/bin/perl use PadWalker qw(peek_my); use strict; use warnings; use Data::Dumper; sub peeker { my $l = shift; print Dumper(peek_my(++$l)) }; my $outmost = "outmost"; { my $inner = "outer"; print peeker(0); } print peeker(0);


      -Lee

      "To be civilized is to deny one's nature."
        They live in the pad for the anonymous sub that you don't see. Each file is, for all intents and purposes, wrapped in a big anonymous subroutine, which hold the file-scoped lexicals. I'm not sure what PadWalker's doing there--I'll have to go dig into it and see what it's looking at.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found