|No such thing as a small change|
Questions concerning /o regex modifierby Limbic~Region (Chancellor)
|on Nov 29, 2006 at 15:45 UTC||Need Help??|
Limbic~Region has asked for the
wisdom of the Perl Monks concerning the following question:
I am likely getting some of this wrong and I am sure some of the more knowledgeable monks will correct the inaccuracies. The question remains regardless.
The /o regex modifier is an old optimization before qr// existed. If you had a regex that needed variable interpolation before compiling but knew the variable would never change, you could use the /o modifier to only compile the regex once (/$regex/o). In fact, if you broke your promise and modified the variable, the regex still would not be recompiled leading to some potentially buggy code. See perlre for more information.
The qr// operator greatly improved things. See perlop for more details. In my opinion, this pretty much rended the need for /o moot. I am not the only one, diotalevi has /o is dead, long live qr//! to say on the matter as well as this.
Ok, I get it - backwards compatability and TIMTOWTDI. There is a lingering question. It is pointed out here that in newer versions, perl automatically detects when a variable is changed and only recompiles a regex when necessary. This is apparently not documented. I checked perldeltas from 5.6 to 5.9.4 though I may have missed it.
So why is this behavior not documented? Is there any reason not to deprecate /o? I am happy to perlbug a doc patch but I am certainly not the most qualified to do so.
Cheers - L~R