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

Re: CSV cleanup problem...

by tlm (Prior)
on Jun 14, 2005 at 01:51 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://466345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-20 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found