True, but you must beware the subtile bugs that could introduce if you're not careful. Consider the difference between the two following snippets:
# snippet 1:
use Data::Dumper;
my @array;
my %hash = ( 'one' => 1, 'two' => 2 );
foreach ( 1 .. 100 ) {
push @array, \%hash;
$hash{'one'}++;
}
print Dumper \@array;
# snippet 2:
use Data::Dumper;
my %hash = ( 'one' => 1, 'two' => 2 );
my @array;
foreach ( 1 .. 100 ) {
push @array, { %hash };
$hash{'one'}++;
}
print Dumper \@array;
|