in reply to meaning of /o in regexes

My understanding, which is confirmed by your tests, is that when you use the /o modifier, any variables within the regex will only be interpolated the first time the regex is seen.

This appears to be similar in effect to using the qr// op to create your regexes in advance. However, using qr// has the advantage that you can pre-compile your regexes in sections and then combine them in the m// and s/// operators in different combinations.

A few things I haven't seen an explanation for (they may exist, I just haven't seen them):

  1. Why does the qr// operator accept the /o midifier?
  2. If you combine one or more parts defined with qr// in a regex with some non-precompiled stuff, do you still get the advantage of precompilation?


    my $re_int = qr/[+-]?\d+/; my $re_exp = qr/[Ee][+-]?$re_int/; if ($str =~ m/^(?:$re_int\.)?$re_int$re_exp?$/ ) { print "I think I got a valid int or float"\n"; }
  3. If there was a non-compiled var reference in the above m//, do I still get any benefit from pre-compiling the other parts?
  4. What happens if I add a /o modifier to the m// above?
  5. If one or more of the per-compiled parts (and/or the non-precompiled parts) contains capture brackets, was there any benefit (in performance terms) from pre-compiling some parts?

I did once attempt to systematically benchmark these to try and determine what coptions and combinations of options had greatest benefit from the performance standpoint, but the process is fraught with gotchas.

Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.