AGCT 0 370 1
AGAG 0 32 0
TGAA 2 233 0
AGGT 3 52 1
####
use strict; # before anything else
use Sort::Fields;
use Data::Dumper;
open(INP,"data.txt") || die "where's the file eh?";
my @data=;
chomp (@data); # remove new line characters
print "before sorting...\n";
print Dumper @data;
#sort the data on the 2nd and the 4th field
#this is numeric sort, as indicated by the "n"
my @sorted = fieldsort '\t', [ '2n', '4n' ], @data;
print "after sorting...\n";
print Dumper @sorted;
####
before sorting...
$VAR1 = 'AGCT 0 370 1';
$VAR2 = 'AGAG 0 32 0';
$VAR3 = 'TGAA 2 233 0';
$VAR4 = 'AGGT 3 52 1';
after sorting...
$VAR1 = 'AGAG 0 32 0';
$VAR2 = 'AGCT 0 370 1';
$VAR3 = 'TGAA 2 233 0';
$VAR4 = 'AGGT 3 52 1';