Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2016-10-25 04:13 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (314 votes). Check out past polls.