in reply to CSV EOL Question
The default for the eol attribute is undefined, so the parser can parse records ending on any valid line ending: \r, \r\n, and \n. To produce records, the CSV object should know to do line endings, hence you need to set eol.
It is way to late now to change the default to be sensible and use $/ on print, which would have been a fine choice in the beginning.
As print takes a reference, why not simplify the code and make it faster?:
my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, eol => $/ }); open my $fh, ">:encoding(utf8)", $filename or die "$filename: $!"; $sth = $dbh->prepare ($query) or # No need to put "'s around $query error ($q, "Problem with database call"); if ($sth->execute) { # not using RaiseError? while (my $ref = $sth->fetch) { # fetching data by ref is faster $csv->print ($fh, $ref); } }
Enjoy, Have FUN! H.Merijn
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: CSV EOL Question
by jrod16 (Initiate) on Jan 22, 2014 at 18:13 UTC | |
by Tux (Canon) on Jan 22, 2014 at 18:28 UTC |
In Section
Seekers of Perl Wisdom