in reply to Re: Commas in quoted CSV records
in thread Commas in quoted CSV records

Please don't promote parse () when reading from streams. This is error prone

use strict; use warnings; use Text::CSV_XS; open my $h_in, "<", "S:/RFax-L7.txt" or die "RFAX: $!"; open my $h_sr, ">", "S:/sorted.csv" or die "Sorted: $!"; open my $h_rj, ">", "S:/rejected.csv" or die "Rejected: $!"; my $csv_in = Text::CSV_XS->new ({ binary => 1 }); my $csv_out = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); while (my $row = $csv_in->getline ($h_in)) { if ($row->[9] == 32) { $csv_out->print ($h_sr, $row) } else { $csv_out->print ($h_rj, $row) } } $csv_in->eof or $csv_in->error_diag (); close $_ for $h_in, $h_sr, $h_rj;

The prints that ikegami used will work fine too, but with the above code, you are more flexible, as you can alter the fields before writing them and still be sure the output is still valid.

The OP sais Text::CSV_XS is already installed. Upgrading might give more functionality, but for a simple task like this you might not need it. To upgrade Text::CSV_XS you will need the matching installer. You seem to be on windows, reading your example, which means either ActivePerl or Strawberry, which will most likely also be somewhere in your START menu

Strawberry

C:> cpan Text::CSV_XS

ActivePerl

C:> ppm update Text::CSV_XS

Enjoy, Have FUN! H.Merijn