Can someone help me understand the output of this Perl program:
use Data::Dumper;
my %hash;
$hash{hello} = "foo";
$hash{hello}{world} = "bar";
print $hash{hello} . "\n";
print $hash{hello}{world} . "\n";
print Dumper(\%hash);
And the conclusion:
foo
bar
$VAR1 = {
'hello' => 'foo'
};
Where does "foo" come from? Why is it not printed out with a dump truck?
Please note that if I change the order of assignments:
use Data::Dumper;
my %hash;
$hash{hello}{world} = "bar";
$hash{hello} = "foo";
print $hash{hello} . "\n";
print $hash{hello}{world} . "\n";
print Dumper(\%hash);
My conclusion is what I expect:
foo
$VAR1 = {
'hello' => 'foo'
};
EDIT: I know I use strict;will catch this, but I'm more interested in knowing how the string "foo" is still printed.
tster source
share