Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Parsing CSV

by kennethk (Abbot)
on Apr 03, 2014 at 17:12 UTC ( #1080976=note: print w/ replies, xml ) Need Help??


in reply to Parsing CSV

The right answer, as choroba and davido say, is don't roll your own: Text::CSV is well tested and already handles standard escapes.

Hypothetically, if you wanted to roll your own, you'd probably want to write a state machine that parsed your strings character by character. You would track if you have passed an even number of double quotes, and if so, empty the buffer onto your array. You'd probably also want to be aware that "" is sometimes used to represent the " literal in the context of a string; in general, you need to know the escaping rules followed for any formatted text object you parse.

Or, you know, you could download code from CPAN.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Parsing CSV
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2015-07-06 22:28 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 (84 votes), past polls