in reply to Re: confused with a hash which contains reversed keys
in thread confused with a hash which contains reversed keys

<nitpick>If all of the OP's hash keys consist of two letters, as in the example data, your code works fine. However, nothing in the 'spec' indicates that this condition is always true. What if the hash is like:

%hash = ( CAB => 31, BAC => 11, ABC => 42, );

</nitpick>

Replies are listed 'Best First'.
Re^3: confused with a hash which contains reversed keys
by ikegami (Patriarch) on Dec 03, 2007 at 22:15 UTC

    At best, it works great for that hash. At worse, you'd have to change the sort criteria.

    sub get_key { my $key1 = $_[0]; my $key2 = reverse $key2; return (sort $key1, $key2)[0]; }

    Either way, the concept I proposed works fine.