"SHAUNAGHH","","","Hawaiian Properties, Ltd.","4","911","Cost Recovery Systms",40,6,32,0,1,1,"01/10/2009","13:33","ADM4968A3E0FA34",0x2000003,1,0,"EVERYONE",6754 "SHAUNAGHH","","","","","","Cost Recovery Systms",40,10,32,0,1,1,"01/10/2009","13:33","ADM4968A3E0FA34",0x2000004,1,0,"EVERYONE",6754 #### #!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; #### # remove commas from quoted text strings; $text = "Aaron,\"1223 Main St, USA\",555-555-1212"; print " INBOUND \$text is equal to: $text\n"; $text =~ s/("[\w\ ]*),([\w\ ]+")/\1\2/g; print " OUTBOUND \$text is equal to: $text"; # This produced output as follows: # INBOUND $text is equal to: Aaron,"1234 Main St, USA",555-555-1212 # OUTBOUND $text is equal to: Aaron,"1234 Main St USA",555-555-1212