It is difficult to divine from your question but my guess is that you want to tag each letter in a word with it's rank in reverse alphabetic order. If that is the case your "bioinfo" example should actually be "5313241" since "f" comes before "i" and "n". This script works by building a hash table of letters in the word with their rank in reverse alpha order.

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


In reply to Re: how do i sort hash values? by johngg
in thread how do i sort hash values? by tweety

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.