Is this a bug in Perl (nested hash)?

John R. Comeau comeaujr at sd.conexant.com
Tue Apr 11 20:55:26 CDT 2000


~sdpm~
I have the following test program to demonstrate a problem I was
having in my code:

#!/usr/local/bin/perl5.005

use strict;

my %hash;

if ($hash{key0})
{
	print "A: true\n";
}
if (exists $hash{key0}{key00})
{
	print "B: true\n";
}
if ($hash{key0})
{
	print "C: true\n";
}

if ($hash{key1})
{
	print "D: true\n";
}
if ($hash{key1}{key10})
{
	print "E: true\n";
}
if ($hash{key1})
{
	print "F: true\n";
}

print "\nKEYS\n", join ("\n", sort keys %hash), "\n";

__END__


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.

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