in reply to RE: Re: lookbehind
in thread lookbehind

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.

Replies are listed 'Best First'.
RE: RE: RE: Re: lookbehind
by httptech (Chaplain) on May 08, 2000 at 03:30 UTC
    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).