As previous poster has indicated, a hash of arrays appears to be what you want....
my % phoneDirectory=(
'Shirley'=> [ '555-0001', '555-0002' ],
'Michael' => [ ‘555-MIKE' ],
'Fred' => [ '555-FRED']
);
#access numbers for Shirley
say $_ for @{$hash{'Shirley'}};
As to your second question, something like:
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.