Couple of comments:
  1. Reread lhoward's post. Those two modules might save you a lot of headaches. Your regex, for example, will not allow for embedded or escaped commas (assuming you ever get any).
  2. @record = split( /\s*,\s*/o, $_); is better written as @record = split /\s*,\s*/;.
  3. I'm not commenting on the meat of your node as you already have tons of good comments about that.
The /o modifier is not necessary if an interpolated variable is not in the regex. Perl automatically compiles the regex only once if it's a straight regex with no variable interpolation (I've made this mistake in posts here, too. See Mastering Regular Expressions, second edition, p159).

The /o modifier can be useful if you have a regex like /\s+${someword}ing/o. If that variable's value never changes, then using /o to force the regex compiler to only compile the expression once is good. However, if you use it to compile an expression with a variable whose value may change, then you're in trouble. The variable's value in the regex will be stuck in the first value and never get updated. The following code illustrates the danger:

while (<SOMEFILE>) { chomp; $found = 1 if $user =~ /$_/o; }
If $user isn't the first one in SOMEFILE, then $user will never match. Incidentally, you can get around this limitation with anonymous subroutines. merlyn has an excellent article about this.

This node was brought to you by the letter "O".


In reply to (Ovid) RE: Regexp glitch while parsing record in CSV by Ovid
in thread Regexp glitch while parsing record in CSV by greenhorn

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.