Brain Goo

Carpe Crap ‘em

Brain Goo header image 2

 

 

perl howto push a hash onto an array

August 12th, 2008 · No Comments

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!

Tags: How Tos · Programming · perl

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment