Jeff 'japhy' Pinyan wrote:
On Jul 23, Tom Allison said:
($lineExtract, $_) = /(^\w+\.dat\|)(.+)$/o;
(I like to add the regex option 'o' at the end to improve performance.)
This is a common misconception. The purpose and effects of the /o
modifier (as well as the /s and /m modifiers) are unclear to a lot of
Perl programmers out there. I'll make a PSA now and try to clear things
up a bit.
The /o modifier tells the internal regex compiler that, after this regex
has been compiled 'o'nce, it is never to be compiled again. "Well, what
good is that?" you ask. For your average regex, there is absolutely no
difference, no change in performance: /foo/ and /foo/o are identical.
The place where the /o modifier matters is when there are variables
inside the regex, e.g. /^$field: (.*)/. The /o modifier says that,
after the regex has been compiled for the first time -- which means that
all the variables in it have been interpolated -- *that* compiled regex
will take the place of the regex with the variables in it. Any changes
to your variables will be ignored, for the rest of the program. There's
no way to reverse the effect of /o.
If you are running regex without variables, like in this case, it does
improve things if you are doing this through a loop within your code.
Otherwise they are identical.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>