faqts : Computers : Programming : Languages : Perl : Common Problems : Hashes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

45 of 54 people (83%) answered Yes
Recently 10 of 10 people (100%) answered Yes

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";
}