in reply to Re^2: Sort a 2D array based on 2 columns
in thread Sort a 2D array based on 2 columns
... 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.#!/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";
|
|---|
| 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 |