in reply to Address of anonymous hash
It's exactly the reverse. An anonymous hash needs to be created every time you assign it, because the only thing you can store is a reference to it. The difference shows in the two programs:
#!perl -w use strict; use Data::Dumper; my @hashes; for (1..2) { push @hashes, { foo => 'bar' }; }; $hashes[0]->{baz} = 1; print Dumper $hashes[1]; # { foo => 'bar' }
Your expectation would change this to the following:
<c> #!perl -w use strict; use Data::Dumper; my @hashes; my $constant_hash = { foo => 'bar' }; for (1..2) { push @hashes, $constant_hash; }; $hashes[0]->{baz} = 1; print Dumper $hashes[1]; # { foo => 'bar', baz => 1 }
|
|---|