Once you take away what doesn't matter, and boil it down to a simplified test script, you're left with this:
@f = <DATA>; foreach $line (@f) { @AB = split("\t", $line); @AA = sort { $a->[1] <=> $b->[1] } @AB; foreach $temp (@AA) { print "@$temp\t", "\n"; } } __DATA__ AA 34 AB 22 AC 12
...which indeed has the appearance of not running.
If you modify the script to be strict compliant, you have this:
use strict; use warnings; use diagnostics; my @f = <DATA>; foreach my $line (@f) { my @AB = split("\t", $line); my @AA = sort { $a->[1] <=> $b->[1] } @AB; foreach my $temp (@AA) { print "@$temp\t", "\n"; } } __DATA__ AA 34 AB 22 AC 12
And when you run that, you get:
Can't use string ("AA 34 ") as an ARRAY ref while "strict refs" in use at mytest.pl line 12, <D +ATA> line 3 (#1) (F) Only hard references are allowed by "strict refs". Symbolic references are disallowed. See perlref. Uncaught exception from user code: Can't use string ("AA 34 ") as an ARRAY ref while "strict refs" in use at mytest.pl line 12, <D +ATA> line 3. at mytest.pl line 12, <DATA> line 3.
Now why might we be getting a "strict refs" violation? Probably because inside your sort routine, you're dereferencing elements of an array that don't hold a reference.
Once you solve that, the next problem will be to sort rows based on columns, rather than columns based on columns.
Dave
In reply to Re: sorting first column
by davido
in thread sorting first column
by vis1982
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |