This could also be called how to make an arrays of hashes. The basic idea is to create a list of items that when iterated, returns individual hashes.
use Data::Dumper;
my @array;
push @array, {'key1' => 'value1', 'key2' => 'value2'};
push @array, {'key1' => 'value1', 'key2' => 'value2'};
push @array, {'key1' => 'value1', 'key2' => 'value2'};
print Dumper(@array);
Will give you:
$VAR1 = {
'key2' => 'value2',
'key1' => 'value1'
};
$VAR2 = {
'key2' => 'value2',
'key1' => 'value1'
};
$VAR3 = {
'key2' => 'value2',
'key1' => 'value1'
};
Snazzy!
Did you find this post useful or have questions or comments? Please let me know!
Pingback: mikerochford.com » Howto push a hash onto an array
Pingback: Python HOWTO Push a Dict on to a List (push a hash on to an array) | Brain Goo