We don't bite newbies here... much | |
PerlMonks |
Re^3: will you explain what's going on?by maard (Pilgrim) |
on Oct 27, 2004 at 10:23 UTC ( [id://402944]=note: print w/replies, xml ) | Need Help?? |
At compile time, Perl creates an entry for $namedisplay in the appropriate lexical pad. Thus every lookup for that variable will find the lexical.
Does this mean that space for all variables in all nested blocks is pre-allocated at compile time? If so that means that even lexicals in blocks of deeper level than current one are accessibe from current block (if I understood you right), i.e. But I used to think (no, I don't know perl internals) that on entering each block that block's 'my' variables are created(allocated) in some 'lexicals stack', probably replacing lexicals with the same name from upper blocks. So this is really interesting: which of this two approaches is used in Perl? Perl doesn't (always) clear lexical variables with refcounts of zero at scope exit (it's an optimization). Reasonable. But what about initialization of variable on each loop pass? If I just write my $var;, the variable is being assigned undef (or empty list for array/hash). But my $var='foo' if $bool effect is still unclear to me. Consider this: If $name wasn't cleared, as you say, 'c' would spread to the end of loop. Or maybe I'm just missing something obvious? :)
In Section
Seekers of Perl Wisdom
|
|