I was expecting the underlying anonymous hashes to be replaced, but they are not.use strict; use warnings; require Data::Dumper; my $foo = { # blessed one => 1, two => 2, six => 6, }; bless $foo, q{Number::3ch}; my $bar = { # not blessed one => 1, two => 2, six => 6, }; sub foo { # pass by ref my $ref = shift; $ref->{one} = q{One}; $ref = {}; # why won't this replace the underlying hash? return $ref; } # try on blessed reference print Data::Dumper::Dumper($foo); foo $foo; print Data::Dumper::Dumper($foo); # try on unblessed reference print Data::Dumper::Dumper($bar); foo $bar; print Data::Dumper::Dumper($bar);
Results:
Questions:$VAR1 = bless( { 'six' => 6, 'two' => 2, 'one' => 1 }, 'Number::3ch' ); $VAR1 = bless( { 'six' => 6, 'two' => 2, 'one' => 'One' }, 'Number::3ch' ); $VAR1 = { 'six' => 6, 'one' => 1, 'two' => 2 }; $VAR1 = { 'six' => 6, 'one' => 'One', 'two' => 2 };
In reply to unexpected behavior on hash passed by reference by perlfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |