in reply to Problem when - use strict and -w
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem when - use strict and -w
by GertMT (Hermit) on Jul 15, 2009 at 03:22 UTC | |
by ikegami (Patriarch) on Jul 15, 2009 at 05:08 UTC | |
by GertMT (Hermit) on Jul 15, 2009 at 10:15 UTC | |
by ikegami (Patriarch) on Jul 15, 2009 at 13:59 UTC | |
by Anonymous Monk on Jul 15, 2009 at 10:43 UTC | |
by GertMT (Hermit) on Jul 15, 2009 at 12:04 UTC |