in reply to Re: confused with a hash which contains reversed keys
in thread confused with a hash which contains reversed keys
Note that the outcome will either contain the key 'AB' or 'BA', but you don't have control over which one occursSo sort the keys before adding...
my %uniq; for ( keys %hash ) { my $reordered_key = join sort split ''; $uniq{$reordered_key} += $hash{$_}; } # still untested
The alphabetically first one will be used (ie AB, rather than BA even if AB doesn't occur).
update: Fixed ikegami's failing test case
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: confused with a hash which contains reversed keys
by ikegami (Patriarch) on Dec 03, 2007 at 13:44 UTC | |
by Anonymous Monk on Dec 03, 2007 at 14:57 UTC | |
|
Re^3: confused with a hash which contains reversed keys
by Anonymous Monk on Dec 03, 2007 at 13:39 UTC |