Is this a bug in Perl (nested hash)?

Alan Stewart astewart at
Wed Apr 12 12:48:33 CDT 2000

On 12 Apr 00, at 8:23, Chris Radcliff wrote:

>"John R. Comeau" wrote:
>> Checking for the existence of a nested key like $hash{key0}{key00}
>> causes $hash{key0} to exist.  Is that the way it's supposed to work?
>> I would think that merely checking for the existence of
>> $hash{key0}{key00} would not cause $hash{key0} to exist.
>I ran this program and got:
>... which is what I would expect. Why is this unexpected? At no time did
>($hash{key1}) return true, for instance, and neither will (exists
>$hash{key1}). You get key0 and key1 in the keys result because you
>inherently dereferenced them to get to key00 and key10.
>I haven't tried it with warnings turned on, but I have the sinking
>suspicion that Perl will yell about using an uninitialized value because
>you're dereferencing a variable that doesn't contain a reference. Anyone
>willing to try?

I ran it and got:
C: true
F: true


which I think is the expected results, since $hash{key0} and $hash{key1} are 
autovivified with hash reference values, which are not false values. Also no -w 
warnings. Perl 5.004.

Chris, what is the actual value of $hash{key0} and $hash{key1} for you?

The definition of exists says that it takes any expression as long as the end 
result is a hash use, so I suspect that the non-autovivification feature applies 
only to the last part of the expression (not the $hash{key0} in this case). You 
would need to nest the exists checks for hash of hashes.

John, what did yours print? You didn't say !!


The posting address is: san-diego-pm-list at

List requests should be sent to: majordomo at

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at> .
This is the general rule for most mailing lists when you need
to contact a human.

More information about the San-Diego-pm mailing list