![]() |
|
No such thing as a small change | |
PerlMonks |
Re: usage of if on nested hash creating empty slot for non existing valueby Anonyrnous Monk (Hermit) |
on Jan 29, 2011 at 09:36 UTC ( [id://885005]=note: print w/replies, xml ) | Need Help?? |
I am not able to understand why an empty slot is created. The feature is called "autovivification". When you dereference a non-existing element, such as {LEVEL2}->{LEVEL2_2}, the element (the LEVEL2 hashref entry here) is automagically being created as needed.
Here, in order to check if the entry BAR is defined, a hash(ref) with an entry FOO is being created. The value associated with the entry FOO is created as another hash(ref) which could potentially hold the checked-for entry BAR. You might argue this doesn't make sense when just testing for existence or definedness, but that's the way it's currently implemented. See the threads turned up by the above google search for more in-depth discussion.
In Section
Seekers of Perl Wisdom
|
|