in reply to Regexp glitch while parsing record in CSV

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".