#!/usr/bin/perl -w use strict; use Data::Dumper; my $username = "PerlMonk"; my $password = "VeryGoodPassword"; my @email_addresses = ( "Monk1", "Monk2", "Monk3" ); my %Record1 = ( username => $username, password => $password, emailAddress => [@email_addresses] ); my %Record2 = ( username => 'SomeOtherPerlMonk', password => 'AntoherVeryGoodPassword', emailAddress => ["monka", "monkb", "monkc"], ); my @AoH; push (@AoH, {%Record1}); #{%Record1} allocates new memory #for the anonymous hash, makes a copy, #of the whole hash table, then adds a #reference to that anon hash #to the array @AoH (similar to a C pointer). push (@AoH, {%Record2}); print Dumper \@AoH; $username = "XXXXXXXXXXXXXXXXXXXX"; # the record in AoH is unchanged because $username was copied # into that record #print Dumper \@AoH; #un-coment to see same thing again print "\nDumping records....\n"; foreach my $record (@AoH) { foreach my $key (keys %$record) { if ( ref ($record->{$key}) eq 'ARRAY' ) { print "$key => @{$record->{$key}}\n"; } else { print "$key => $record->{$key}\n"; } } print "\n"; } __END__ $VAR1 = [ { 'password' => 'VeryGoodPassword', 'emailAddress' => [ 'Monk1', 'Monk2', 'Monk3' ], 'username' => 'PerlMonk' }, { 'password' => 'AntoherVeryGoodPassword', 'emailAddress' => [ 'monka', 'monkb', 'monkc' ], 'username' => 'SomeOtherPerlMonk' } ]; Dumping records.... password => VeryGoodPassword emailAddress => Monk1 Monk2 Monk3 username => PerlMonk password => AntoherVeryGoodPassword emailAddress => monka monkb monkc username => SomeOtherPerlMonk