in reply to Array of hash

Here's what I ended up with:
#!/usr/bin/perl -w use strict; my @list = qw(1 Mike testing 2 Richard testing2 3 David Testing3); my @records; my $r; my $c = 1; foreach my $f (@list) { if ($c == 1) { $r->{id} = $f } if ($c == 2) { $r->{name} = $f } if ($c == 3) { $r->{subject} = $f; print "Pushing Id: $r->{id}\t Name: $r->{name}\t Subject: $r->{sub +ject}\n"; # print "Anonymous hash: $r\n"; push(@records, $r); $c = 1; $r = {}; next; } $c++; } foreach (@records) { print "ID: $_->{id}\t"; print "Name: $_->{name}\t"; print "Subject: $_->{subject}\n"; }
If you comment out the line where I assign $r to a new anonymous hash and uncomment the line where I print out the value of $r, you'll notice that it refers to the same hash. Since $r and $array[0], $array1, and $array2 are all references to the same hash, when you replace a value with one reference, you're replacing it in the one hash.

For further proof, move the right curly bracket from beneath the $c++; line to the end of the file. That will loop through @records each time and show you the change in the one hash. Solution? Make a new hash each time through the loop.

(Damian Conway describes references as "fingers pointing at the moon". You're copying fingers, but not making new moons.)