No, the key will only autivify when you assign a value to it.
Prove:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %h;
print $h{key} ? $h{key} : "nokey";
print "\n", Dumper (\%h);
See? The hash stays emtpy.
Update:
exists, defined and the check for truth do different things. Consider:
#!/usr/bin/perl
use strict;
use warnings;
my %h = ( a => "", b => undef, c => "true");
for ( qw(a b c d) )
{
print "key: $_ is " . ($h{$_} ? "" : "not ") . "true\n";
print "key: $_ is " . (defined $h{$_} ? "" : "not ") . "defined\n"
+;
print "key: $_ is " . (exists $h{$_} ? "" : "not ") . "existing\n
+";
}
#key: a is not true
#key: a is defined
#key: a is existing
#key: b is not true
#key: b is not defined
#key: b is existing
#key: c is true
#key: c is defined
#key: c is existing
#key: d is not true
#key: d is not defined
#key: d is not existing
|