in reply to Re: meaning of /o in regexes
in thread meaning of /o in regexes
Just a note: none of this applies if you are using qr the way it's meant - as the entire regex for m// or s/// as in $qr = qr/./; $_ = 'abc'; m/$qr/; s/$qr//; $_ =~ $qr. All of these more normal uses of expressions benefit from the precompilation. This note is about interpolating qr objects into other regular expressions which is different.
Starting from the top: I created the short sample program and then dumped it's opcode tree to see what it actually does. From this I can say that interpolating qr objects into another regular expression saves nothing. The objects are all concatenated (meaning stringification) and then compiled for the regex. If you add the /o modifier to any m// or s/// operation then it binds the compiled form to that location in hte opcode tree. There is no reason for that to change just because you used a qr in the regex or not. If you read Dominus' remarks on that at Dirty Secrets of the Perl Regex Engine then that will be clear.
The answers to your questions (in order):
- I don't know
- no (you are penalized)
- no (you are penalized)
- the same thing it always does
- no (you are penalized)
$qr = qr/./; 'a' =~ /$qr$qr/; __DATA__ C:\>perl -MO=Concise qr.pl e <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 5 qr.pl:1) v ->3 5 <2> sassign vKS/2 ->6 3 </> qr(/./) s ->4 - <1> ex-rv2sv sKRM*/1 ->5 4 <> gvsv s ->5 6 <;> nextstate(main 5 qr.pl:3) v ->7 d </> match() vKS ->e 7 <$> const(SPECIAL Null)[t5] s ->8 c <|> regcomp(other->d) sK/1 ->d 8 <1> regcreset sK/1 ->9 >> This is where you see the two [qr] expressions >> being fetched as global scalar values, >> concatenated and *then* just above this the >> regex is compiled. b <2> concat[t4] sK/2 ->c - <1> ex-rv2sv sK/1 ->a 9 <> gvsv s ->a - <1> ex-rv2sv sK/1 ->b a <> gvsv s ->b
I'm working off of the three references http://perl.plover .com/Rx/, and perlop (the gory quoting part. See also pp_hot.c for pp_concat which doesn't do anything special for qr magic. It's just strings at that point.
__SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re^2: meaning of /o in regexes
by BrowserUk (Patriarch) on Dec 06, 2002 at 17:00 UTC | |
by diotalevi (Canon) on Dec 06, 2002 at 17:12 UTC | |
by BrowserUk (Patriarch) on Dec 06, 2002 at 17:28 UTC | |
by diotalevi (Canon) on Dec 06, 2002 at 17:36 UTC |