Is this a bug in Perl (nested hash)?

Chris Radcliff chris at velocigen.com
Wed Apr 12 10:23:32 CDT 2000


~sdpm~


"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?

~chris
~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