Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Parsing CSV

by kennethk (Monsignor)
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 meditating upon the Monastery: (9)
As of 2014-08-27 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (237 votes), past polls