#!c:\perl\bin\perl.exe -w use strict; use diagnostics; # Open a filehandle READFILE and associate it with my data full of CSV records open (READFILE,"; # Open two more files to write to keepers in SORTED rejects in REJECT open SORTED,">","s:\\sorted.txt" or die "Couldn't open SORTED.TXT file: $!\n"; open REJECT,">","s:\\reject.txt" or die "Couldn't open REJECT.TXT file: $!\n"; # preprocess $lines to remove embedded commas in quoted fields # The following line worked when I declared the contents of $::lines as "Aaron,\"1234 Main St, USA\",555-555-1212" # it produced the output "Aaron,"1234 Main St USA",555-555-1212" # but when I moved it into this program incorporating it into the loop it doesn't work! foreach $::lines (@lines) { $::lines =~ s/("*),(,")/\$1\$2/g; # Import each line into an array seperating by the commmas. @::field = split(/,/, $::lines); # Test to see if the 10th field contains "32", these we keep if ($::field[9] != 32) { print REJECT "* rejected not 32 * $::lines"; print "* REJECTED * $::lines"; } else { print SORTED "$::lines"; print "\$ KEEPER ==> $::lines"; } } close READFILE; close SORTED; close REJECT;