I have a file which is tab delimited(a hit from a DB). I would like to first store say the first and tenth item on each(row) as well as the entire row in a hash. And then build an array of hashes from 2nd,3rd,...... rows respectively. I would then sort each of the rows by score and ID(which are the first and 10th elements of each row) and print the row with the best score.

I have tried this out and it seems I was just able to pick only one row:

my @CHIMP = <CBLAT>;#CBLAT hold the file to be processed</p> my %hITS; my $score; my @bestHITS; if(!@CHIMP){</p> my $nm = "no_match"; next} my $cblast = shift @CHIMP;#process blat output lines(r +ows)</p> my @row = split(/\t/,$cblast);</p> unshift @{$hITS{$score}},{MATCH=>$row[0],qID=>$row[9], +cLINE=>$cblast};#keep score,query id and whole lines in hash</p> @{$hITS{$score}} = sort {$b->{MATCH} <=> $a->{MATCH} | +| $a->{qID} cmp $b->{qID}} </p>@{$hITS{$score}};#sort by match score/ +query ID</p> foreach my $key (@{$hITS{$score}}){ my $hits = $key->{cLINE}; push @bestHITS, $hits;#keep sorted lines in ar +ray last;}

my program seem to be processing only the first row. I need hints/snippets!

In reply to Building an array of hashes, and then sorting keys with each hash by odegbon

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.