Re: print statement creates key in hash with reference to empty array??



rhorizon74 wrote:
Thanks for the help.

That explains what is happening (i had used the exists approach to work
around).
But it does seem bogus that for a simple print statement i need to
check each and every level. I havent seen too many languages do
something like this (i may be wrong).
But a print statement shouldnt really be creating any data.

It is not the print(), it is the fact that you are trying to access the value of the ABC key. If hashes didn't autovivify, then you won't be able to do this:


   $hash{key1}{key2}{key3} = 'value';

before you actually create all the keys explicitly:

   $hash{key1}             = {};
   $hash{key1}{key2}       = {};
   $hash{key1}{key2}{key3} = 'value';

Autovivification is a Good Thing (tm).

--Ala

.



Relevant Pages