First, since what you're doing looks suspiciously like database operations, might you be better off using
DBD::CSV? It uses the same CSV engine as
Text::CSV::Simple but provides a database interface for dealing with the data.
Second, I'd concur with the other posters who point out that the data you have can't really be parsed as CSV directly, but needs to be munged first. Your best bet is to get whoever outputs the data to properly escape the embedded quotes by doubling them or putting backslash or some other escape character in front of them. If you can't get that to happen, you'll need to munge the data to put those escapes in first. Whether it's even possible to munge the data with one of the supplied regexen depends on the complexity of your data. For example, it's quite possible to have both commas and quotes embedded in a field so this is a valid CSV record of three fields:
"a",",foo,""bar"",""baz"",","b"
If that occurs without the escapes, it will look like this:
"a",",foo,"bar","baz",","b"
And I doubt there's a regex that could figure out which commas are separators and which quotes are delimiters from that.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.