http://www.perlmonks.org?node_id=1080976


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.