Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: CSV cleanup problem...

by tlm (Prior)
on Jun 14, 2005 at 01:51 UTC ( #466345=note: print w/replies, xml ) Need Help??


in reply to CSV cleanup problem...

This doesn't directly answer your question, but is this link of any use to you? (This link, BTW, asserts that Text::CSV_XS can handle embedded commas, so I'm a bit puzzled by your question.)

Update: Thanks to jZed for the cluebrick. FWIW,

split /(?<=")\s*,\s*(?=")/, $string
splits the OP's sample input into
0 '"title"' 1 '"Some Name, "some wierd title""' 2 '"555-555-5555"'
and it is a trivial matter to remove the leading and trailing double quotes from each field; e.g.:
my @fields = map { s/^"(.*)"\z/$1/; $_ } split /(?<=")\s*,\s*(?=")/, $string;

the lowliest monk

Replies are listed 'Best First'.
Re^2: CSV cleanup problem...
by jZed (Prior) on Jun 14, 2005 at 02:54 UTC
    The problem in devnul's data isn't embedded commas, or embedded quote marks (both of which Text::CSV_XS handles fine as long as the embedded quotes are escaped (by your choice of escape character). The problem with the data is un-escaped embedded quotes marks. My guess is that unless there are some rather arbitrary known things about the embedded quote marks, it will be darn tough to deal with them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://466345]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2018-02-18 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (257 votes). Check out past polls.

    Notices?