in reply to how do i sort hash values?
use strict; use warnings; my @words = qw{bioinfo alpha different}; foreach my $word (@words) { print qq{$word\n}; my $rhRank = rank($word); print qq{$_ -- $rhRank->{$_}\n} for split m{}, $word; } print qq{\n}; sub rank { my $word = shift; my %seen = (); my $index = 0; my $rhRank = { map {$_, ++ $index} sort {$b cmp $a} grep {! $seen{$_} ++} split m{}, $word }; }
When run for three words it produces
bioinfo b -- 5 i -- 3 o -- 1 i -- 3 n -- 2 f -- 4 o -- 1 alpha a -- 4 l -- 2 p -- 1 h -- 3 a -- 4 different d -- 7 i -- 4 f -- 5 f -- 5 e -- 6 r -- 2 e -- 6 n -- 3 t -- 1
I hope I have guessed correctly and this is of use.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. |
|---|