> > Merely referencing a key in a hash sets it into the hash,
> though with a
> > value of undef.
>
> This turns out not to be the case. In Perl, merely referencing a key
> in a hash doesn't change the hash. Some non-Perl hash implementations
> do change the hash in those circumstances, though, so your confusion
> is understandable.
>
> my %last_name;
> $last_name{'fred'} = 'flintstone'; # creates key 'fred' in hash
> my $x = $last_name{'barney'}; # does not create key 'barney'
>
Ah, but you have to be careful if you start diving too deeply into
nested hashes...
[EMAIL PROTECTED]:~ 09:24 AM]$ perl -e '
use warnings;
use strict;
use Data::Dumper;
my %family;
$family{"fred"}{"wife"} = "Wilma";
my $x = $family{"barney"}{"wife"};
print Dumper(\%family),"\n";
'
$VAR1 = {
'barney' => {},
'fred' => {
'wife' => 'Wilma'
}
};
In this case, merely referencing a key in a hash does, in fact, change
the hash. To be safe, always test each step of the way when working with
nested hashes to see if the key exists.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>