Restating the question, why do duplicate entries of hashes in an array reference the first entry in Perl? Please correct my terminology if I am mistaken but, when I push identical hash references into an array with the code below:
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my @array;
my %hash = (foo => 'foo', bar => 'bar');
for (1..3) {
push @array, \%hash;
}
print Dumper @array;
I get the following result:
$VAR1 = {
'bar'=> 'bar',
'foo'=> 'foo'
};
$VAR2 = $VAR1;
$VAR3 = $VAR1;
I expected to see the following result:
$VAR1 = {
'bar'=> 'bar',
'foo'=> 'foo'
};
$VAR2 = {
'bar'=> 'bar',
'foo'=> 'foo'
};
$VAR3 = {
'bar'=> 'bar',
'foo'=> 'foo'
};
Is this behavior because of a fundamental Perl concept or because of Data::Dumper
?