Entry
How do I access elements in a hash of arrays?
How do I loop over an array within a hash?
Jul 15th, 2001 02:39
Per M Knutsen,
When accessing elements in hashes of arrays, arrays of hashes and other
complex data-structures you should pay careful attention top the syntax
you are using. The following example illustrates how you can retrieve
and loop over an array of a hash:
#!/usr/bin/perl
use strict;
use warnings;
# Create array
my @names = ["Rick","Ray","Charles"];
# Create hash
my %myHash = ( "names" => @names );
foreach my $name ( @{$myHash{"names"} } ) {
print $name."\n";
}