After a discussion earlier on composing regular expressions, I've learned that piecing them together causes the whole thing to be recompiled anyway, so it's simpler to just put together a string than to avoid having incomplete regex parts.

So I'm looking at rewriting all the regex parts as plain strings. In my experiment, I changed a qr to a q and added a (?: ) around everything. I know the modifiers that will be used on the ultimate one that ties them all together, so I don't have to make them self-contained. I know how to stick it in the opening grouping syntax if I have to.

Now clearly using the single-q form of a string won't take $var things within it. But other than that, what exactly do I need to watch out for? What's different between the parsed single-quote-string literal and the qr literal?

I've also verified that simply not having the "self-containment" modifiers (xs-im) doesn't make it generate any different code. I'm supposing that these affect compile-time interpretation of the contents, and would not "do" anything with respect to making it generate worse code than simply having the grouping construct alone (?: ) would do. Furthermore, superfluous non-capturing parens shouldn't hurt it anyway since the optimizer blows past them, right? (But I'm sure there are cases where the groupers are not redundant and I can tell it matches the same or at least solves the same problem without them, but is technically different so the optimizer can't help there.)

I will note, though, that writing component qr's helps with error checking and debugging when writing the thing, since it will show the syntax error in a small section. But I can change to q's once it works, so it doesn't compile everything twice.


In reply to differences between parsing qr, qq, and q string contents by John M. Dlugosz

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.