sort 2-d array in perl
hi
i have a 2-d array:
16 14 458
17 14 489
17 16 494
17 15 494
17 18 548
2 0 57
4 0 85
4 2 128
6 2 139
8 2 169
8 4 214
8 6 233
11 6 259
11 8 313
13 8 328
I want to sort it first by the third, and then the second column.
i have the following code but it doesn't seem to work.
any help would be much appreciated.
#!/usr/bin/perl
my $In = "trial.txt";
my $Out = "trialn.txt";
open (Data,"<$In");
open (Datan,">$Out");
my @Data = <Data>;
my @sorted = sort {$a->[2] <=> $b->[2] || $a->[0] <=> $b->[0]} @Data;
print Datan (@sorted);
close Data;
close Datan;
|