http://www.perlmonks.org?node_id=316163

kiat has asked for the wisdom of the Perl Monks concerning the following question:

Hey fellow monks,

Please help enlighten me on the behaviour of "%$hash{'output'}" in the snippet of code below

my %hash = ( 'left_fills' => 'Name: a7', 'main_title' => 'Main Area' ); # call do_output # Simplifed to pass just one hash value do_output( output => \%hash, ); sub do_output { my %hash = @_; my $output = $hash{'output'} || 0; # Dumped 1 (OK) print Dumper($output); # Dumped 2 (OK) print Dumper(%$output); # Dumped 3 (OK) print Dumper($hash{'output'}); # Dumped 4 (Script died) print Dumper(%$hash{'output'}); } # print Dumper($output); $VAR1 = { 'left_fills' => 'Name: a7', 'main_title' => 'Main Area' }; # print Dumper(%$output); $VAR1 = 'left_fills'; $VAR2 = 'Name: a7'; $VAR3 = 'main_title'; $VAR4 += 'Main Area'; # print Dumper($hash{'output'}); $VAR1 = { 'left_fills' => 'Name: a7', 'main_title' => 'Main Area' }; # print Dumper(%$hash{'output'}); Error: Global symbol "$hash" requires explicit package named at test.p +l line...
The dumped output of "$hash{'output'}" is identical to that of "$output". But why does dumping "%$hash{'output'}" cause the script to die?

When I did a "ref" of both "$output" and '$hash{'output'}", the result is HASH for both. I'm puzzled why their behaviour isn't exactly identical.

As usual, thanks in advance :)