(Revised per mdillon's note, but in a different way for speed)my %revhash; while (my ($key, $value) = each %hash) { push @{$revhash{$value}}, $key; } for (sort keys %revhash) { print "$_ => @{$revhash{$_}}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Inverting a hash to get all keys for this value
by mdillon (Priest) on Oct 09, 2000 at 21:11 UTC | |
by merlyn (Sage) on Oct 09, 2000 at 21:13 UTC |