Non-capturing parens ((?:...)) and flags ((?x-sim:...)) are used only in the parsing/compilation of the regular expression - they don't contribute nodes of their own to the resulting regexp program, but they may change what nodes something else compiles to.

For example, qr{.} gives the node 'SANY', while qr{.}s gives 'REG_ANY'.

However the compiler cannot stitch together subpatterns in compiled form, so whenever you build up a pattern from two previously qr'd patterns, or a qr'd pattern and some new text, perl constructs the stringified form of the new pattern and then compiles this new string from scratch.

Because of this, it is usually simpler for this sort of code to construct the string representing the complete pattern (with the added benefit that your diagnostics become more readable), so I'd tend to use:

my @days = qw( Sun Mon Tue Wed Thu Fri Sat ); my $days_re = join '|', map "\Q$_\E", @days; $days_re = qr{$days_re};
rather than putting an additional qr{} in the map.

Hugo


In reply to Re^5: qr// with /e? by hv
in thread qr// with /e? by tkil

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.