in reply to arrays, hashes, dereferencing confusion - need help

kudos for "use strict" and "use warnings"

Understanding the error message can give clues as to what could the matter be...
"Reference found where even-sized list expected at arrayTest_monk.pl line 38."

is a warning that tells you that perl is trying to make a hash out of a passed list, and since hashes are associative (they have key/value pairs) hence for the set to be complete an even-sized list has to be passed so that each key would have its associated value..That wouldn't be detectable were you not invoking warnings! consider the following:

use strict; use warnings; my @keyVal1 =qw(something 1 another 2); my @keyVal2 = qw(SOMETHING 1 ANOTHER); my %hash1 = @keyVal1; my %hash2 = @keyVal2; use Data::Dumper; print Dumper(\%hash1); print "\n"; print Dumper(\%hash2);

Since each member of @deRefHashArray is a hash then inspecting the warnings would show you that you haven't dereferenced it appropriately..

have been of great benefit to me and so wish they would be to you too..

Here's your code after minor touches to get you started
#!/usr/local/bin/perl use Data::Dumper; use strict; use warnings; my $hashArrayRef; $hashArrayRef = [{ 'dateOfBirh' => '22 March 1971', 'firstName' => 'Ronnie', 'lastName' => 'Smith' }, { 'timeNow' => '14 April 1972', 'firstName' => 'Claudia', 'lastName' => 'Winkleman' }]; print Dumper(\@$hashArrayRef); #Properly dereferenced..compare output print "\n"; print Dumper(@$hashArrayRef); print "\n"; for (my $counter = 0; $counter <= $#$hashArrayRef; $counter++) { while ( my ($key, $value) = each(%{@$hashArrayRef[$counter]}) +) { print "$key => $value\n"; } }
wish you a nice Perl journey...


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.