The issue with your posted code can be traced back to your not using
Text::CSV to parse the data, which I find ironic given your node title (Update: previous title "Text::CSV"). With your splitting above, your data values are
$x = '"001"', not the
$x = '001' you seem to expect. If you had turned on warnings, you would have gotten
Argument ""2"" isn't numeric in numeric comparison (<=>) repeatedly, since
"2" is clearly not numeric.
Text::CSV will automatically clean up the quotes, and thus your numbers would have been properly be interpreted as numbers. A la:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $sheet;
my $count = -1;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attr
+ibute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
my @rows = ();
while ( my $row = $csv->getline( *DATA ) ) {
push @rows, $row;
}
my $header = shift @rows;
foreach my $row ( sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] }
+@rows ) {
print join( ',', @$row ), "\n";
}
__DATA__
Name,Score,State
"001","67","CA"
"2","67","CA"
"12","63","FL"
"1","72","IL"
"1","32","AZ"
See Use strict warnings and diagnostics or die.