On 5.24:

$ perl -E 'my $re = qr{(?x: PAT )}; say $re' (?^u:(?x: PAT ))

As, ^ is short for d-imnsx, and u overrides d, I suppose that's effectively equivalent to something like:

(?d-imnsx:(?u-d:(?x: PAT )))

Also on 5.24:

$ perl -E 'my $re = qr{ PAT }msx; say $re' (?^umsx: PAT )

Which, given the same logic, would be:

(?d-imnsx:(?umsx-d: PAT ))

Of course, d can't actually be turned off like that (i.e. -d is illegal):

$ perl -E 'my $re = qr{(?d-imnsx:(?u-d:(?x: PAT )))}' Regexp modifier "d" may not appear after the "-" in regex; ... $ perl -E 'my $re = qr{(?d-imnsx:(?umsx-d: PAT ))}' Regexp modifier "d" may not appear after the "-" in regex; ...

I'm just making the point that both qr{(?x: PAT )} and qr{ PAT }msx end up with nested (?:...) constructs and both have modifiers turned on and off at various points.

"... it occurred to me to ask if you were aware that qr// effectively wraps its object ..."

Yes, I was aware of it; and something I learned a long time ago (2008, I think). I came across a situation where compiled regexes were being stored, retrieved and recompiled. This was under 5.8 (I think), and the modifiers were somewhat different, but the basic scenario was:

$ perl -E 'my $re = qr{ PAT }msx; say $re; $re = qr{ $re }msx; say $r +e; $re = qr{ $re }msx; say $re; say "..."' (?^umsx: PAT ) (?^umsx: (?^umsx: PAT ) ) (?^umsx: (?^umsx: (?^umsx: PAT ) ) ) ...

I imagine you're familiar with the doco but, for others who might be interested, see these sections of perlre: "Modifiers"; "(?adlupimnsx-imnsx)"; "(?:pattern)".

— Ken


In reply to Re^8: Recognizing 3 and 4 digit number by kcott
in thread Recognizing 3 and 4 digit number by htmanning

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.