turquoise_man has asked for the wisdom of the Perl Monks concerning the following question:
#!/bin/perl -w use Data::Dumper; use parse::CSV; my @csvdata; # open the file and parse my $file = Parse::CSV->new( file => 'darkint.csv', ); open($outfile, ">", 'sorted.csv') or die $!; while (my $val = $file->fetch) { push(@csvdata,$val); } if($file -> errstr){ print "$errstr error in parsing\n"; } # here we define a subroutine to sort our data in the correct manner sub tableSorter($$){ my ($row1,$row2) = @_; my $column10comparison = $row1->[9] cmp $row2->[9]; if($column10comparison != 0) { return $column10comparison; } my $column33comparison = $row1->[32] cmp $row2->[32]; if($column33comparison != 0) { return $column33comparison; } return $row1->[33] <=> $row2->[33]; } # now sort my @sorted_dat = sort tableSorter @csvdata; # arrange the sorted array into cav format my $temp = join "\n",map{ $_=join ", ", @{$_}}@sorted_dat; print $outfile $temp; # close the output file close($outfile);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: memory problems parsing large csv file
by BrowserUk (Patriarch) on Aug 24, 2009 at 13:58 UTC | |
by turquoise_man (Initiate) on Aug 24, 2009 at 14:18 UTC | |
|
Re: memory problems parsing large csv file
by salva (Canon) on Aug 24, 2009 at 13:44 UTC | |
|
Re: memory problems parsing large csv file
by Tanktalus (Canon) on Aug 24, 2009 at 19:33 UTC | |
by Tux (Canon) on Aug 26, 2009 at 07:31 UTC | |
|
Re: memory problems parsing large csv file
by Anonymous Monk on Aug 24, 2009 at 13:44 UTC | |
|
Re: memory problems parsing large csv file
by NiJo (Friar) on Aug 24, 2009 at 18:05 UTC | |
by BrowserUk (Patriarch) on Aug 24, 2009 at 18:26 UTC |