Why aren't you using Text::CSV_XS for output too?
#!/usr/bin/perl -w use strict; use Text::CSV_XS qw( ); my $qfn_in = 'data.txt'; open(my $fh_in, '<', $qfn_in) or die("Can't open file \"$qfn_in\": $!\n"); my $fh_out = \*STDOUT; my $csv_in = Text::CSV_XS->new({ sep_char => ',', eol => $/ }); my $csv_out = Text::CSV_XS->new({ sep_char => "\t", eol => $/ }); my $number = 10; while ( my $row = $csv_in->getline($fh_in) ) { $csv_out->print($fh_out, [ "Olah:", $number++, @$row[2,5,3,0,4], ]); }

Mind you, the output format is slightly different than yours. (It will quote all fields or only necessary fields depending on option always_quote).

It could use error checking, but you didn't have any either.


In reply to Re: Problem when - use strict and -w by ikegami
in thread Problem when - use strict and -w by GertMT

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.