in reply to Regexp glitch while parsing record in CSV
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:
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.while (<SOMEFILE>) { chomp; $found = 1 if $user =~ /$_/o; }
This node was brought to you by the letter "O".
|
|---|