Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Parsing Parsing CSV only returns the second line of the file

by Tux (Monsignor)
on Sep 01, 2012 at 15:40 UTC ( #991167=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Parsing Parsing CSV only returns the second line of the file
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-30 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls