in reply to sort and hash

Ok, perhaps you need a tutorial on how to dynamically create a hash of data, and how to sort the data. I have constructed a little sample program below which will give you an idea on how to do this.
use strict; use Data::Dumper; # for investigating data structures my %data; # load data into hash of arrays while (<DATA>) { chomp; my @fields = split/,/; $data{$fields[0]} = \@fields; # first column = hash key } print "\%data - \n", Dumper(\%data); # We will transform the hash into a sorted array # sorted on the 3rd column (score) my @array = sort { $a->[2] <=> $b->[2] } map { $data{$_} } keys %data; print "\@array - \n", Dumper(\@array); # Output sorted data lines print "Sorted data - \n"; foreach (@array) { printf "%s\n", join ',', @{$_}; } __DATA__ Sequence1,0001,80 Sequence2,0002,20 Sequence3,0003,40 Sequence4,0004,100 Sequence5,0005,70
The code above will output the following results:
%data - $VAR1 = { 'Sequence1' => [ 'Sequence1', '0001', '80' ], 'Sequence2' => [ 'Sequence2', '0002', '20' ], 'Sequence3' => [ 'Sequence3', '0003', '40' ], 'Sequence4' => [ 'Sequence4', '0004', '100' ], 'Sequence5' => [ 'Sequence5', '0005', '70' ] }; @array - $VAR1 = [ [ 'Sequence2', '0002', '20' ], [ 'Sequence3', '0003', '40' ], [ 'Sequence5', '0005', '70' ], [ 'Sequence1', '0001', '80' ], [ 'Sequence4', '0004', '100' ] ]; Sorted data - Sequence2,0002,20 Sequence3,0003,40 Sequence5,0005,70 Sequence1,0001,80 Sequence4,0004,100
Where %data contains a hash of arrays of data. @array is a sorted array of array of data. And use join to put the array of data back to its original form.

To insert a key/value pair into a hash, use the syntax below:
my %data; $data{key} = value;
or
%data->{key} = value;
The line of code my @array = sort { $a->[2] <=> $b->[2] } map { $data{$_} } keys %data; translates to English: Retrieve the data arrays of for each key in the %data hash, sort the data arrays based on the 3rd data column, and put them in the new array @array. And thus this will give you a sorted array of array of data.

If you only want to sort the data based on a certain column, why not try out the Schwartzian Transform invented by Randal Schwartz (merlin):
@sorted_array = map {$_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (split/,/)[2] ] } # retrieve the third key @original_array;
Where @original_array is just an array of data strings.