<?xml version="1.0" encoding="windows-1252"?>
<node id="860645" title="Re: Array of Hashes in subroutines." created="2010-09-18 12:33:12" updated="2010-09-18 12:33:12">
<type id="11">
note</type>
<author id="525442">
lima1</author>
<data>
<field name="doctext">
You almost had it. Just pass a reference to the hash to your function with \%hash. You can access the elements without dereferencing with the -&gt; operator.
 
&lt;code&gt;
#!/usr/bin/perl
use strict;

sub display {
    my $ref01 = shift;

    foreach my $key (sort keys %{$ref01}) {
        print "$key: $ref01-&gt;{$key}[0] $ref01-&gt;{$key}[1] $ref01-&gt;{$key}[2]\n";
    }
}

my %hash1;

$hash1{'fruit'} = ['apple', 'orange', 'plum'];
$hash1{'vegetable'} = ['leek', 'carrot', 'peas'];

display (\%hash1);

foreach my $j (sort keys %hash1) {
    print "$j: $hash1{$j}[0] $hash1{$j}[1] $hash1{$j}[2]\n";
}
&lt;/code&gt;</field>
<field name="root_node">
860644</field>
<field name="parent_node">
860644</field>
</data>
</node>
