Is this a bug in Perl (nested hash)?

C. Abney cabney at
Wed Apr 12 01:28:40 CDT 2000

On Tue, 11 Apr 2000, 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.

Hmm, that was pretty cryptic (what I said) when I look at it more closely.
What I meant was, if you use exists to check any of the values (even the
nested ones) it should return false (unless you have a bug!)

Most people come to this question trying to use 'defined()' on the key,
where the hash key has been brought to life via autovivification.

perlfaq4, "Why does defined() return true on empty arrays and hashes?"
takes you to the entry for 'defined' in perlfunc for a cursory overview.
I'm sure there must be more elsewhere.

Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein.  -- Larry Wall                                     C. Abney


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