in reply to Re^4: array or hash reference
in thread array or hash reference
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;
Dave
|
|---|