Re: Shrink large file according to REG_EXP
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Thu, 17 Jan 2008 09:38:08 GMT
"b" == bugbear <bugbear@xxxxxxxxxxxxxxxxxxxxxxxxx> writes:
b> Uri Guttman wrote:
>>>>>>> "nc" == nolo contendere <simon.chao@xxxxxxx> writes:
nc> On Jan 16, 2:17 pm, Uri Guttman <u...@xxxxxxxxxxxxxxx> wrote:
>> >> >>>>> "nc" == nolo contendere <simon.c...@xxxxxxx> writes:
>> >> >> nc> check out /REGEX/o
>> >> >> obsolete and probably useless.
>> >> nc> really? is this since 5.10?
>> since at least when qr// came in. also dynamic regexes (those with
>> interpolation) are not recompiled unless some variable in them
>> changes. this is what /o was all about in the early days of perl5. so
>> it's purpose of not recompiling has been moot for eons. and qr// even
>> makes it even more useless.
b> I won't ask you lots of questions - but do you have a link
b> to this info that I can read - it's of (substantial) interest
b> to me.
this should be in perlop under the regexp quote like ops but it doesn't
mention that /o is useless now. the faq covers it. and 5.6 is pretty old
so /o has been useless for years.
perlfaq6: What is /o really for? (code snipped)
The /o option for regular expressions (documented in perlop and
perlreref) tells Perl to compile the regular expression only once. This
is only useful when the pattern contains a variable. Perls 5.6 and later
handle this automatically if the pattern does not change.
Since the match operator m//, the substitution operator s///, and the
regular expression quoting operator qr// are double-quotish constructs,
you can interpolate variables into the pattern. See the answer to "How
can I quote a variable to use in a regex?" for more details.
Versions of Perl prior to 5.6 would recompile the regular expression for
each iteration, even if $pattern had not changed. The /o would prevent
this by telling Perl to compile the pattern the first time, then reuse
that for subsequent iterations:
In versions 5.6 and later, Perl won't recompile the regular expression
if the variable hasn't changed, so you probably don't need the /o
option. It doesn't hurt, but it doesn't help either. If you want any
version of Perl to compile the regular expression only once even if the
variable changes (thus, only using its initial value), you still need
the /o.
You can watch Perl's regular expression engine at work to verify for
yourself if Perl is recompiling a regular expression. The use re 'debug'
pragma (comes with Perl 5.005 and later) shows the details. With Perls
before 5.6, you should see re reporting that its compiling the regular
expression on each iteration. With Perl 5.6 or later, you should only
see re report that for the first iteration.
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
.
- Follow-Ups:
- Re: Shrink large file according to REG_EXP
- From: Ilya Zakharevich
- Re: Shrink large file according to REG_EXP
- From: bugbear
- Re: Shrink large file according to REG_EXP
- References:
- Shrink large file according to REG_EXP
- From: thellper
- Re: Shrink large file according to REG_EXP
- From: nolo contendere
- Re: Shrink large file according to REG_EXP
- From: Uri Guttman
- Re: Shrink large file according to REG_EXP
- From: nolo contendere
- Re: Shrink large file according to REG_EXP
- From: Uri Guttman
- Re: Shrink large file according to REG_EXP
- From: bugbear
- Shrink large file according to REG_EXP
- Prev by Date: Re: Shrink large file according to REG_EXP
- Next by Date: Re: Shrink large file according to REG_EXP
- Previous by thread: Re: Shrink large file according to REG_EXP
- Next by thread: Re: Shrink large file according to REG_EXP
- Index(es):
Relevant Pages
|