in reply to Aggregating Lines from a CSV who lines match a particular field and save those matches based on that matching field name

Don't open and close the file over and over again. Take advantage of the fact that your file is sorted.
my $fh; my $last; while (<>) { my ($file) = /^([^,]+),/; if (!defined($last) || $file ne $last) { open($fh, '>', "$file.txt") or die($!); } print $fh $_; $last = $file; }
  • Comment on Re: Aggregating Lines from a CSV who lines match a particular field and save those matches based on that matching field name
  • Download Code