since a regular expression without variable interpolation
doesn't have the potential to change between uses, Perl only
ever compiles it once. however, when a regular expression
contains a variable to be interpolated, the value of the
variable can potentially be different every time, so Perl
compiles the regular expression with the current value of
the variable every time it is used. the 'o' modifier tells
Perl that the values of interpolated variables should be
treated as constant, so that Perl will only compile the
regular expression 'once' no matter how many times you use
it.
i'm not sure whether or not using 'o' on a regexp without
any variable interpolation adversely affects performance,
but it is simply unnecessary. | [reply] |
Great explanation, thanks! I'm sure this point has confused others
in the past, because I've seen more experienced Perl programmers
than me make the same mistake (probably where I picked it up from).
| [reply] |