in reply to Re^2: Sort a 2D array based on 2 columns
in thread Sort a 2D array based on 2 columns

Code it in Perl then ...
#!/usr/bin/perl -w use strict; my @mega = ( ["AGCT", "0", "370", "1"], ["AGGT", "3", "52", "1"], ["TGAA", "2", "233", "0"], ["AGAG", "0", "32", "0"] ); open ( fh, ">junk.txt" ); for my $row (@mega) { print fh (join ":", @{$row}) . "\n"; } close fh; my $shellout = <<`SHELL`; sort -n -t: -k2,4 junk.txt SHELL print "$shellout\n";
... if you expend some effort you can find away of avoiding writing the array to a file as sort does accept input form STDIN also, read the man page.

Replies are listed 'Best First'.
Re^4: Sort a 2D array based on 2 columns
by lostjimmy (Chaplain) on Apr 26, 2009 at 15:02 UTC
    How is this a great (or even good) solution? Sorting within perl is easier to read, understand, and is less code. It also doesn't require forking another process just to do something so simple as sorting.