in reply to How to remove duplicate key/value pairs in hash of array
You can eliminate duplicate values by inverting the hash (turning key/value pairs into value/key pairs) and then re-inverting.
%hash = (a => 1, b => 1, c => 2); %hash = reverse %hash; # key/value -> value/key %hash = reverse %hash; foreach $key ( keys %hash ) { print $key, " => ", $hash{$key}, "\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to remove duplicate key/value pairs in hash of array
by bdalzell (Sexton) on Feb 04, 2009 at 15:18 UTC |
In Section
Seekers of Perl Wisdom