Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: CSV EOL Question by Tux
in thread CSV EOL Question by jrod16

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found