#!/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);
In reply to memory problems parsing large csv file by turquoise_man
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |