my %uniq; for (keys %hash){ if (exists $uniq{scalar reverse $_}){ $uniq{scalar reverse $_} += $hash{$_}; } else { $uniq{$_} = $hash{$_}; } } # untested
Note that the outcome will either contain the key 'AB' or 'BA', but you don't have control over which one occurs (it's not in the spec ;-)
In reply to Re: confused with a hash which contains reversed keys
by moritz
in thread confused with a hash which contains reversed keys
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |