sort can take a block which dictates the sort criteria. Consider:
use strict; use warnings; use Text::xSV; my $data = <<'END_DATA'; 02/28/2009|02062672169||4.99|9801|1.0| 02/28/2009|78513836100||4.96|9639|1.0| 02/28/2009|71171973992||19.99|9749|1.0| 02/28/2009|01463314931||19.99|9802|1.0| END_DATA open my $inFile, '<', \$data or die "Failed to open data file: $!"; my $csv = Text::xSV->new (fh => $inFile, sep => '|'); my @rows; push @rows, $_ while $_ = $csv->get_row; @rows = sort {$a->[1] <=> $b->[1]} @rows; print join "\n", map {join '|', map {$_ || ''} @$_} @rows;
Prints:
02/28/2009|01463314931||19.99|9802|1.0| 02/28/2009|02062672169||4.99|9801|1.0| 02/28/2009|71171973992||19.99|9749|1.0| 02/28/2009|78513836100||4.96|9639|1.0|
In reply to Re: Sort by specific column
by GrandFather
in thread Sort by specific column
by mraja_23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |