Very simple CSVs can be parsed with the split function. But yours has separators AND delimiters, this is already not a simple CSV and this would amply justify a module such as Text::CSV. However, looking at your specific example, if you really want to do it yourself, you could first remove quote marks and then split on commas:
$line =~ s/"//g; my @fields = split /,/, $line;
(It could also be done the other way around, first splitting on commas and then removing quote marks.) But now, either way, think about what will happen when your input line is:
"New York, NY","Entries","Entry Time","Visit Length","Browser"
Both ways, it will break with an unwanted extra field, and you'll be out of luck. We do use quite commonly split to process simple CSV files (although our separator is usually a semi-colon rather than a colon), but only (well almost only) on CSV files that we have created beforehand and in which we fully master the content and we know we are not gonna have a bad surprise.

On files coming from an outside organization on which you have no control, don't do it. In your case, the simple fact that there are both separators and delimiters is a sign that there is a clear danger that your process is probably going to break on the first special case coming up. The Text::CSV module is really a much more robust alternative in any case where you don't control everything yourself.


In reply to Re: Match a comma between two words by Laurent_R
in thread Match a comma between two words by Stefany

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.