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.
Thank you for your help and your patience.
Jean-Louis
I have two problems to pass an array of hashes and I can't find out how to solve them.
The output:#!/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"; * }
Obviously, the array is incomplete and I can't dereference it. It would be great if someone could be able to modify that script.fruit: ARRAY(0x8775818) vegetable: ARRAY(0x878fea8) fruit: apple orange plum vegetable: leek carrot peas
Thank you for your help and your patience.
Jean-Louis
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Array of Hashes in subroutines.
by lima1 (Curate) on Sep 18, 2010 at 16:33 UTC | |
by jlnh (Novice) on Sep 18, 2010 at 18:24 UTC | |
by abhijithtk (Novice) on Sep 19, 2010 at 08:11 UTC | |
Re: Array of Hashes in subroutines.
by oko1 (Deacon) on Sep 18, 2010 at 18:22 UTC | |
by AnomalousMonk (Archbishop) on Sep 19, 2010 at 00:24 UTC | |
Re: Array of Hashes in subroutines.
by toolic (Bishop) on Sep 18, 2010 at 21:18 UTC | |
Re: Array of Hashes in subroutines.
by suhailck (Friar) on Sep 18, 2010 at 17:06 UTC | |
Re: Array of Hashes in subroutines.
by biohisham (Priest) on Sep 19, 2010 at 07:17 UTC |
Back to
Seekers of Perl Wisdom