#!/usr/bin/perl use strict; use warnings; # An example of using an array of hashes my @MasterArray = (); my %SubHash1 = ( 'ABC' => 2, 'DEF' => 3, ); my %SubHash2 = ( 'GHI' => 5, 'JKL' => 6, ); my %SubHash3 = ( 'MNO' => 8, 'PQR' => 9, ); # Now use push to append a reference to the hash into the array: push @MasterArray, \%SubHash1; push @MasterArray, \%SubHash2; push @MasterArray, \%SubHash3; # Extract the reference and build a temporary hash to access its elements: foreach my $ArrayElement (@MasterArray) { print "-----[ New Hash from Array ]---------------\n"; my %CurrentHash = %$ArrayElement; foreach my $CurrentKey (sort keys %CurrentHash) { my $CurrentValue = $CurrentHash{$CurrentKey}; print "Key {$CurrentKey} contains '$CurrentValue'\n"; } } print "-------------------------------------------\n"; exit; __END__ #### C:\Steve\Dev\PerlMonks\P-2013-10-27@0815-Array-of-Hashes>perl testAoH.pl -----[ New Hash from Array ]--------------- Key {ABC} contains '2' Key {DEF} contains '3' -----[ New Hash from Array ]--------------- Key {GHI} contains '5' Key {JKL} contains '6' -----[ New Hash from Array ]--------------- Key {MNO} contains '8' Key {PQR} contains '9' -------------------------------------------