Paul wrote:

>> > Lexicals aren't in the symbol table.
>> >   my $foo;
>> > *can't* be accessed as $pack::foo, because it isn't IN a package.
>> 
>> true.
>> 
>> > Locals, on the otherhand, *have* to be package variables that can
>> > be tracked by $pack::foo syntax. So how can
>> >   my @bar;
>> > allow
>> >   local $bar[2];
>> > to localize an element of @bar which isn't traceable through a
>> > package name? It obviously works, but I don't see *how*.
>> 
>> there is no package variables in Perl, only global or lexical.
> 
> Not so -- ALL package variables in Perl *are* global, but likewise all
> global variables in Perl are package vars. Even $_ is technically
> $main::_ so that
> 
>   $_ = 'foo';
>   package bob;
>   print $main::_."\n";
> 
> prints "foo" and the newline.

you are inventing the phrase "package variable" but i wont' argue with.

> 
>> local doesn't work on what you refer to as package or my-variable.
> 
> package variables aren't my() variables -- my()'s are lexical.
> package vars are in some package...though you can say
> 
>   package;
> 
> to make no package the default, that just means you have to specify
> one.
> Thus,
> 
>   package;
>   $x = 1;
> 
> is an error, just as if strict vars were in effect, whereas
> 
>   package;
>   $foo::x = 1;
> 
> is fine.
> 
>> it works on the stack.
> 
> What stack? Not the function call stack.....
> You mean there's a stack for symbol table entries?
> NOW we're getting somewhere! That makes sense, and I hope it's true.

why are you keep bring on the topic of symbol table with local? what makes 
you think symbol table has anything to do with the following statement:

my @x = (1..5);
{
        local $x[0] = -1;
}

your original question is "how can local localize $x[0] given that @x isn't 
in the symbol table?"

i am telling you that you should forget about symbol table, package 
vairable(which you invent because all Perl knows is global and lex. 
variable), scretchpades and/or trying to show how how many ways(there are 
virtually endless ways, i can tell you that much right now) you can access 
a variable prefixing it with it's package name. the reason why Perl can 
localize $x[0] even @x is a lexical variable is becasue when Perl enters a 
block and sees the 'local $x[0]' statement, it puts this tmp value in the 
stack (not the function stack and there is no symbol stable entries stack), 
it's a run time stack where Perl keeps track of all the local variables. 
all statements inside this block, therefore, see the localized version. 
when the block exit, the stack is destoried so the localized value goes 
away and the original value is restored.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to