You didn't show how you tried my suggestions, so I'm not sure why it didn't work for you. Here's a more complete example, which takes your sample input and sorts it by the frequencies (largest to smallest), outputting with a header built to your latest spec. Make sure you understand what's going on in the sort {block}: what $tags{$a} means, for instance. I'm sorting on the values, not the keys. The keys go into $a and $b, and I'm using those as keys into the hash to sort on the values.

#!/usr/bin/perl use warnings; use strict; my %tags; # hash to store tags/freqs while(<DATA>){ chomp; my($tag, $freq) = split; # split the line on whitespace $tags{$tag} = $freq; # save the tag and freq in the hash } # sort the hash numerically on its values, descending for my $tag ( sort { $tags{$b} <=> $tags{$a} } keys %tags ){ my $freq = $tags{$tag}; # put the freq for $tag in $freq my $header = make_header($tag, $freq); # make the header print ">$header\t$tag\t$freq\n"; # print it out } sub make_header { my $tag = shift; # get parameters my $freq = shift; my $r = int(rand(500000)); # pick a random number return "HWTI_${freq}_$r$tag"; # build the header } #input data __DATA__ CCCDEDFFFES 45 EEBBBBGGGBB 1700 BBBCDDERFGG 850
#output >HWTI_1700_494932EEBBBBGGGBB EEBBBBGGGBB 1700 >HWTI_850_10814BBBCDDERFGG BBBCDDERFGG 850 >HWTI_45_187939CCCDEDFFFES CCCDEDFFFES 45

In reply to Re^3: Sorting issue by aaron_baugher
in thread Sorting issue by bluray

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.