in reply to Building an array of hashes, and then sorting keys with each hash
my program seem to be processing only the first row.
The rows are in @CHIMP. You grab the first row using my $cblast = shift @CHIMP;. You only execute that once, and you never touch @CHIMP again.
$score is never assigned a value, yet you use it all over the place. Boooo! for disabling warnings or ignoring them. I think you meant $hITS{score} rather than $hITS{$score}.
Anyway, this is what you want:
my @hITS; while (<CBLAT>) { chomp; my ($score, $qID) = ( split /\t/ )[ 0, 9 ]; push @hITS, [ $_, $score, $qID ]; } @hITS = sort { $b->[1] <=> $a->[1] || $a->[2] cmp $b->[2] } @hITS; for (@hITS) { print $_->[0], "\n"; }
Update: I suppose you did say AoH. It's more readable, especially if you save the other fields:
my @hITS; while (<CBLAT>) { chomp; my %row; @row{qw( score qID )} = ( split /\t/ )[ 0, 9 ]; push @hITS, \%row; } @hITS = sort { $b->{score} <=> $a->{score} || $a->{qID} cmp $b->{qID} } @hITS; for (@hITS) { print "score: $_->{score} qID: $_->{qID}\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Building an array of hashes, and then sorting keys with each hash
by odegbon (Initiate) on Dec 30, 2009 at 07:05 UTC | |
by ikegami (Patriarch) on Dec 30, 2009 at 12:41 UTC | |
by odegbon (Initiate) on Dec 31, 2009 at 05:41 UTC | |
by ikegami (Patriarch) on Jan 02, 2010 at 00:40 UTC | |
by odegbon (Initiate) on Jan 03, 2010 at 22:19 UTC | |
| |
by odegbon (Initiate) on Dec 31, 2009 at 07:46 UTC |