in reply to Generate Array of Hashes WITHOUT References
The question has been answered already. I thought I would add a little bit more explanation.
When we write %hash = ('a', 'b', 'c', 'd'); this is the same as saying %hash = ('a' => 'b', 'c' => 'd'); because the => are just fat commas. So, when you push the hash onto an array, push @AoH, %hash this is just the same as push @AoH, ('a', 'b', 'c', 'd'); which will simply push the elements one by one onto @AoH, losing the structure of the hash or array that you are pushing.
Small technical point. You don't know if at the end of this you get @AoH = ('c', 'd', 'a', 'b'); or @AoH = ('a', 'b', 'c', 'd'); because the ordering of the keys in a hash is arbitrary.
This is the whole reason why references were added in Perl 5.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generate Array of Hashes WITHOUT References
by RonW (Parson) on Sep 09, 2014 at 23:17 UTC |