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

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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-08-17 16:58 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (182 votes). Check out past polls.