Here's an example of sorting an array by a specified column.
#!/usr/bin/perl;
use strict;
use warnings;
my @array = sort howtosort <DATA>;
foreach (@array){
chomp;
print "$_\n";
}
sub howtosort{
my @flds_a = split(/\|/, $a);
my @flds_b = split(/\|/, $b);
$flds_a[2] cmp $flds_b[2]; #compare key fields to sort
}
__DATA__
1780438|20110709|0000007704000000000000004888|7704|48881|PE|08/12/2008 11:38:54|0|1000.00
1780437|20110708|0000007704000000000000004882|7704|48882|PE|08/12/2008 11:38:54|0|1000.00
1780436|20110707|0000007704000000000000004889|7704|48887|PE|08/11/2008 11:38:54|0|1000.00
1780435|20110703|0000007704000000000000004881|7704|48888|PE|08/12/2008 11:38:54|0|1000.00
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159