Is this a bug in Perl (nested hash)?

Alan Stewart astewart at spawar.navy.mil
Wed Apr 12 12:48:33 CDT 2000


~sdpm~
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:
>KEYS 
>key0 
>key1
>
>... 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

KEYS 
key0 
key1

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 !!

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> 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 happyfunball.pm.org> .
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