I have an array and hash defined as:
my @test_array;
my %test_hash = (
line_1 => 1,
line_2 => 2,
line_3 => 3,
);
I want to add that hash to the array, then modify the hash and push any new versions to the array
push (@test_array, %test_hash);
$test_hash{line_1} = 2;
push (@test_array, %test_hash);
Finally, I need to call a method while passing in each hash in the array, one at a time:
for my $hash (@test_array) {
$self->do_thing(%$hash)
}
However, when I print out the array it appears that both hashes are stored in a single element:
use Data::Dumper;
print Dumper (\@test_array);
### Begin Output ###
$VAR1 = [
'line_1',
1,
'line_3',
3,
'line_2',
2,
'line_1',
2,
'line_3',
3,
'line_2',
2
];
My method call should essentially look like the following, with line_1 => 2 in the hash on the second time through the loop:
$self->do_thing(
line_1 => 1,
line_2 => 2,
line_3 => 3,
);
Can someone please explain why this is all being added to a single array element? I expect that the Dumper output would include a $VAR1 for the first hash pushed, and a $VAR2 for the second - however this is not the case.
Thanks!