in reply to Accessing hash values in a HOH
As previous poster has indicated, a hash of arrays appears to be what you want....
As to your second question, something like:my % phoneDirectory=( 'Shirley'=> [ '555-0001', '555-0002' ], 'Michael' => [ ‘555-MIKE' ], 'Fred' => [ '555-FRED'] ); #access numbers for Shirley say $_ for @{$hash{'Shirley'}};
my %names; while (<>) { my ($first, $last) = split; if ($last) { # add last name to hash element push @{$names{$first}}, $last; } } # print names print @{$names{'John'}};
Caveat: Just taking a break from XCOM, have not compiled or tested above, so send me a message if syntax not quite right and I'll fix it :-)
Updated with comments from Athanasius below..
A Monk aims to give answers to those who have none, and to learn from those who know more.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Accessing hash values in a HOH
by Athanasius (Archbishop) on Feb 23, 2013 at 07:04 UTC | |
Re^2: Accessing hash values in a HOH
by modi2020 (Novice) on Feb 23, 2013 at 16:06 UTC |
In Section
Seekers of Perl Wisdom