in reply to sorting CSV files

TMTOWTDI ... but an array of arrays would work:

#!/usr/bin/perl my $sheet; my $count = -1; while( <DATA> ) { chomp; $count++; # skip header next unless $count; my $row; @$row = split( /,/, $_ ); push @$sheet, $row; } foreach my $row ( sort { $a->[1] <=> $b->[1] } @$sheet ) { print join( ',', @$row ), "\n"; } __DATA__ Name,Score,State Mike,67,CA Rob,63,FL Jim,72,IL Chan,32,AZ
-derby

Replies are listed 'Best First'.
Re^2: sorting CSV files
by argupta (Initiate) on Feb 05, 2009 at 22:43 UTC
    Hello derby, Im working in a similar data sctructure. In my case the csv files are around 26Mb. And I want to sort them with reference to a particular column, and then taking a sorted group, i want to sort them again using a different column. Looking at your earlier solution, I am unable to sort them in a hash table. (Since that is the best way I can think of)

      What hash? There's no hash there, just references to arrays. You can always do a secondary sort:

      foreach my $row ( sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] } +@$sheet ) {
      That construct will sort first by second col and then by the third col.

      -derby