You seem to be assuming that the unescaped quote will never be followed by a comma (or white space and then a comma, or perhaps a newline). Actually, amelinda's use of the word "other" makes me suspect that this assumption is likely true in this particular case. (:

But I felt it important that readers not get the wrong impression about how well such "not really CSV" data can ever be handled in general. You have to draw the line somewhere. As I said, I find it quite reasonable to draw the line at "your embedded quotes must be escaped". But if you cross that line, there still has to be another line such as "your unescaped embedded quotes must not be followed by...".

To be honest, I never seriously considered such an option. And then when you mentioned it, the phrase "that way lies madness" (in an appropriately Halloween voice) came to mind. Then I switched to, "well, that would be fairly easy to add." Then I thought about exactly how to do it and recalled how many times I've seen brilliant people that were regex experts get the "match C-style comments" regex wrong and started to have doubts again.

Perhaps trying something like /'([^']|'(?! *[,\n]))*'/ to match single-quoted fields would work. But I think I'd probably backtrack at this point and say that adding support for that has too high of a risk of introducing bugs. Perhaps making it optional could aleviate that risk when the option isn't selected. Perhaps you have more confidence in your ability to solve that problem correctly than I do in mine. :)

        - tye (but my friends call me "Tye")

In reply to (tye)Re7: parsing CSV file with embedded commas (fortunately, fixed-width) - is unpack the solution? by tye
in thread parsing CSV file with embedded commas (fortunately, fixed-width) - is unpack the solution? by amelinda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.