Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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):

  1. I don't know
  2. no (you are penalized)
  3. no (you are penalized)
  4. the same thing it always does
  5. no (you are penalized)
The penalizing is from having to do a magic_get on the qr ops instead of just reading it as a string and then the overall penalty of doing work more than once (compile the regex for qr, mg_get the stringified form, then compile the larger regex). Or at least that's how I read it. Please correct me if I'm wrong - I am still quite a novice at this.

$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;

In reply to Re^2: meaning of /o in regexes by diotalevi
in thread meaning of /o in regexes by mce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found