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

In reply to Re^2: Commas in quoted CSV records by Tux
in thread Commas in quoted CSV records by generator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.