Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
From perlsub:
Variables declared with "my" are not part of any package and are therefore never fully qualified with the package name.
and again:
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.
and:
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[3] = '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 ydbxmhc@yahoo.com, okay? This one's hurting my brain. :) Paul
Variables declared with "my" are not part of any package and are therefore never fully qualified with the package name.
and again:
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.
and:
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[3] = '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 ydbxmhc@yahoo.com, okay? This one's hurting my brain. :) Paul
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: local element of my() array????
by Abigail-II (Bishop) on Feb 19, 2003 at 01:16 UTC | |
Re: local element of my() array????
by BrowserUk (Patriarch) on Feb 18, 2003 at 23:27 UTC | |
by Anonymous Monk on Feb 19, 2003 at 16:24 UTC | |
Re: local element of my() array????
by steves (Curate) on Feb 18, 2003 at 23:27 UTC | |
Re: local element of my() array????
by xmath (Hermit) on Feb 18, 2003 at 23:30 UTC | |
by steves (Curate) on Feb 18, 2003 at 23:39 UTC | |
by xmath (Hermit) on Feb 19, 2003 at 00:09 UTC | |
by Anonymous Monk on Feb 19, 2003 at 16:36 UTC | |
by Anonymous Monk on Feb 19, 2003 at 16:28 UTC | |
by Anonymous Monk on Feb 19, 2003 at 16:26 UTC | |
Re: local element of my() array????
by extremely (Priest) on Feb 19, 2003 at 06:22 UTC |
Back to
Seekers of Perl Wisdom