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 occurs
So 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
    Sorting like that won't produce consistent results. If EA is present in the original hash but not AE, you'll end up with EA instead of AE. Sort the chars of the key rather than the order in which they are fetched to avoid guessing under which key a particular value is located.
      you have right with the sorting but i can't understand
      what do you mean "Sort the chars of the key "
      how i can do that by using the code of the first answer ?
Re^3: confused with a hash which contains reversed keys
by Anonymous Monk on Dec 03, 2007 at 13:39 UTC
    thanks a lot for your help!It works correctly