in reply to Re: Looping through a hash where some keys are the same
in thread Looping through a hash where some keys are the same
Another option would be a hash of arrays, so that each key was unique, but referred to an array of one or more values:
my %hash = ( 'bob' => [ "section-a", "section-b" ], 'jan' => [ "section-d" ] ); # And to add another.... foreach (qw(section-f section-g)) { push(@{$hash{'paul'}}, $_); } foreach my $k (keys(%hash)) { print "$k => ", join(",", @{$hash{$k}}), "\n"; }
HTH.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Looping through a hash where some keys are the same
by GaijinPunch (Pilgrim) on Feb 18, 2005 at 01:56 UTC | |
by tphyahoo (Vicar) on Feb 18, 2005 at 11:17 UTC |