The easiest way is to do it correctly from the beginning.
sub get_key { join '', sort $_[0] =~ /./g } my %hash; while (<DATA>) { chomp; $hash{get_key($_)}++; } use Data::Dumper; print(Dumper(\%hash)); __DATA__ AB AB AB AC AC BA BA BA CA
$VAR1 = { 'AC' => 3, 'AB' => 6 };
But the same method will allow you to fix your hash. (Added)
sub get_key { join '', sort $_[0] =~ /./g } my %hash; while (<DATA>) { chomp; $hash{$_}++; } my %fixed; foreach my $key (keys %hash) { my $val = $hash{$key}; $fixed{get_key($key)} += $val; } use Data::Dumper; print(Dumper(\%fixed)); __DATA__ AB AB AB AC AC BA BA BA CA
By the way, this is a moderated site, so your post may not appear instantly. Please don't triple post.
In reply to Re: confused with a hash which contains reversed keys
by ikegami
in thread confused with a hash which contains reversed keys
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |