http://www.perlmonks.org?node_id=991167


in reply to Parsing CSV only returns the second line of the file

The outer loop should be written like, more modern and safe (think embedded newlines).

my $csv_in = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); my $csv_out = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, eol => + "\n" }); open my $fh_old, "+<", $file or die Lava::Message ("Can't open origina +l file: $file: $!"); open my $fh_new, ">", $temp or die Lava::Message ("Can't open tempfil +e file: $temp: $!"); $csv->getline ($fh_old); # skip first line. Header?. If empty line, 's +calar <$fh_old>;' is a good option while (my $row = $csv->getline ($fh_old)) { : : $csv_out->print ($fh_new, [ map { $row->[$_] } 0, 2, 1, 3, 0 ]); } $csv_out->print ($fh_new, [ 0, 0.000, 0.000, 0.000 ]); $csv_out->print ($fh_new, [ 0, 0.000, 0.000, 0.000, "END" ]); close $_ for $fh_old, $fh_new;

Enjoy, Have FUN! H.Merijn