For the OP just to emphasize the importance of binary in the case you have a def. of CSV that permits embedded newlines.

For Merijn.

I was going to answer more or less the same to the OT yesterday, but came across a few problems, that made me reinstall the latest versions...

  • One problem was that I used IO::Wrap objects for stdin and stdout and they don't work with the pure perl version, I am not sure why. Maybe it would be better to load IO::Handle directly and have something for those who want efficiency. In this thread I wanted to test the pure perl version as installing an XS module could have been problematic for thew OP. I think that keeping in sync both versions is important...
  • for some reason search.cpan.org gives the version 0.29 Text::CSV_XS but perl -MCPAN -e install qw(Text::CSV_XS)' installs 0.30 the right one I believe if I remember your post on p5p or pm.

    % steph@apexPDell2 (/home/stephan) % % cat conv_comma2pipe_xs.px #!/usr/bin/perl use strict; use warnings; $|++; #use IO::Handle; use IO::Wrap; use Text::CSV_XS; # use DDS; # my $in = IO::Wrap::wraphandle(\*STDIN) or die; # my $out = IO::Wrap::wraphandle(\*STDOUT) or die; # Dump\($in, $out); my $csv_in = Text::CSV_XS->new({ binary => 1, }) or die; my $csv_out = Text::CSV_XS->new({ binary => 1, sep_char => q{|}, eol => qq{\n}, }) or die; while (defined (my $rec = $csv_in->getline(\*STDIN)) ) { { my @fields = @$rec; local $"=q{][}; print {\*STDERR} ".rec [@fields]\n"; } $csv_out->print(\*STDOUT, $rec); } __END__ % steph@apexPDell2 (/home/stephan) % % cat hi1.csv | perl+ -w conv_comma2pipe_xs.px .rec [a][b][c] a|b|c .rec [a][okay, comma][c] a|"okay, comma"|c .rec [a][long line, indeed][end] a|"long line, indeed"|end % steph@apexPDell2 (/home/stephan) % % cat hi1.csv a,b,c a,"okay, comma",c a,"long line, indeed",end
    cheers --stephan p.s I tested on cygwin with perl 5.8.7 and 5.8.8 update: oops forgot the code...

    In reply to Re^2: swapping PIPE for comma in CSV file by sgt
    in thread swapping PIPE for comma in CSV file by dwhite20899

    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.