Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Handling an embedded newline in an unquoted CSV field

by TJPride (Pilgrim)
on Dec 10, 2011 at 14:15 UTC ( [id://942811]=note: print w/replies, xml ) Need Help??


in reply to Handling an embedded newline in an unquoted CSV field

Yes, about all you can do is check if a line is short some fields, and if it is and the next line is also short, put them together. But this is further complicated by the possibility that the newlines could be inside a quoted field, in which case the CSV parsing will choke and you have to figure out a much more complicated way of counting fields. And the file could theoretically not have a header, or the header might not have names for all the fields, in which case figuring out how many fields the file -should- have is difficult as well. And what if the field with the newline is at the very end of the record and unquoted? It'll look like that record is fine and the problem starts on the next record.

This is one of those problems I wish I had an easy answer for as well. I've run into it a number of times while doing data imports for one of my clients.

  • Comment on Re: Handling an embedded newline in an unquoted CSV field

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found