The problem is, it's not a string. That is, there's additional structure. The quotes apparently mean something special, including that you shouldn't split on commas within them. (This quickly raises the question of what it means if there are quotes within quotes, and how you escape quoting, and...soon you're having to work far too hard.) (This is a common situation of course; I sort of wrote about it as if I hadn't seen it before, but it's actually a staple of programming.)

You don't tell us what the actual format is; GrandFather's guess that it's a CSV seems reasonable, but it's just a guess. So, if you're lucky, there's a clear description of what the rules for this CSV format are, and the input you get will reliably follow them, and you can write something to parse that. But the rule here is that parsing is hard -- if you do anything more than the most brute-force simple kind.

If you're really lucky, your input conforms to the standard that the CSV module that was suggested supports, and you don't have to write the parsing yourself.


In reply to Re: split string by comma by dd-b
in thread split string by comma by Anonymous Monk

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.