in reply to confused with a hash which contains reversed keys

You can iterate over the hash, and build a new one:
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 ;-)

Replies are listed 'Best First'.
Re^2: confused with a hash which contains reversed keys
by FunkyMonk (Bishop) on Dec 03, 2007 at 13:31 UTC
    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

      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 ?
      thanks a lot for your help!It works correctly