1-1:80
2-4:72
####
1-2:2196
2-2:180
####
%hash = (
'1-1' => 80,
'1-4' => 26,
'4-4' => 3,
'2-2' => 180,
'2-4' => 72,
'1-2' => 2196
);
$N =2;
%hash = seq_score($N,%hash);
printhash(%hash);
#---sub-----
sub seq_score{
use Tie::IxHash;
tie my %spair, "Tie::IxHash"; #modified
($N,%spair) = @_;
my %topN_pair = ();
my %seq =();
my $t = Tie::IxHash->new(%spair); #set new class
$t->Reorder( reverse $t->SortByValue()->Keys() );#desc sort by value
%topN_pair = $t->Splice(0, $N);
return %topN_pair;
}
sub printhash
{
my %hash = @_;
foreach my $key (sort{$hash{$b}<=>$hash{$a}} keys %hash )
{ next if ($hash{$key} <=1);
print $key, ":", $hash{$key}, "\n"
}
}