|go ahead... be a heretic|
local element of my() array????by Anonymous Monk
|on Feb 18, 2003 at 23:09 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
Variables declared with "my" are not part of any package and are therefore never fully qualified with the package name.
A note about "local()" and composite types is in order. Something like "local(%foo)" works by temporarily placing a brand new hash in the symbol table. The old hash is left alone, but is hidden "behind" the new one.
It's also worth taking a moment to explain what happens when you "local"ize a member of a composite type (i.e. an array or hash element). In this case, the element is "local"ized by name. This means that when the scope of the "local()" ends, the saved value will be restored to the hash element whose key was named in the "local()", or the array element whose index was named in the "local()".
So, if I say my @foo = (0..9); then say local $foo = 'bar'; that a symbol table entry is created? that it is still ignored for every other element of @foo, but that it overrides it my() equivelent element since it, specifically, was local()ized? Ok, this is deeply wierd. Somebody help me get this one? And please feel free to email me at email@example.com, okay? This one's hurting my brain. :) Paul