http://www.perlmonks.org?node_id=860644

jlnh has asked for the wisdom of the Perl Monks concerning the following question:

HI everyone,
I have two problems to pass an array of hashes and I can't find out how to solve them.
#!/usr/bin/perl use strict; sub display(\%) { my $i; my @ref01 = shift; foreach $i (sort keys (%{$ref01[0]})) { print "$i: ${$ref01[0]}{$i} ${$ref01[1]}{$i} ${$ref01[2]}{$i}\n"; } } my (%hash1, $j, $z); $hash1{'fruit'} = ['apple', 'orange', 'plum']; $hash1{'vegetable'} = ['leek', 'carrot', 'peas']; $z = display (%hash1); foreach $j (sort keys (%hash1)) { print "$j: $hash1{$j}[0] $hash1{$j}[1] $hash1{$j}[2]\n"; * }
The output:
fruit: ARRAY(0x8775818) vegetable: ARRAY(0x878fea8) fruit: apple orange plum vegetable: leek carrot peas
Obviously, the array is incomplete and I can't dereference it. It would be great if someone could be able to modify that script.
Thank you for your help and your patience.
Jean-Louis