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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.