Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Writing to csv file

by GrandFather (Saint)
on Mar 03, 2011 at 00:27 UTC ( [id://891133]=note: print w/replies, xml ) Need Help??


in reply to Re: Writing to csv file
in thread Writing to csv file

Using a different character, or even a string of characters, makes no difference to the nature of the problem of the possibility that the separator may validly be part of the data. The much better solution is to quote the separator string in some fashion if it appears in the data. Such quoting is what CSV modules do, albeit with some lack of standardisation in how the quoting is achieved.

True laziness is hard work

Replies are listed 'Best First'.
Re^3: Writing to csv file
by maestromani (Initiate) on Mar 03, 2011 at 10:25 UTC
    Thanks a lot for all the reply. I'm generating csv for crystal report. If i replace , with | Crystal report is not identifying a separate column.. All i did is used "=~ s{,}{::comma::}g;" as advised by John BRs
Re^3: Writing to csv file
by Marshall (Canon) on Mar 05, 2011 at 02:09 UTC
    I don't see any real disagreement here. Some of the databases I work with use "|" instead of "," and disallow "|" as a valid data character - so this "|" within "|" issue does not come up.

    When I generate a CSV file on my own, sometimes I use the "|" instead of "," when I know that "|" is not going to be in the data. I'm just saying that option is possible. Although the format is called "Comma Separated Value", the character can be anything you want, which is what you are saying. Some folks take CSV literally and don't realize that some other character can be used and that standard programs can parse files like that. To parse the general case of a CSV file, I would use one of the Perl modules as this is a very deceptively easy looking, but very hard to implement specification.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-16 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found