in reply to Re^6: Recognizing 3 and 4 digit number
in thread Recognizing 3 and 4 digit number

Oh, and one more thing (so much for my final word in the thread)...

I'm sure you must be, but it occurred to me to ask if you were aware that  qr// effectively wraps its object in a  (?mo-ds:...) ((?^mods:...) from 5.14 onward) non-capturing group? So your preferred usage ends up looking like:

c:\@Work\Perl\monks>perl -wMstrict -le "my $rx = qr{(?x: pattern)}; print qq{perl version $]: $rx}; " perl version 5.008009: (?-xism:(?x: pattern)) perl version 5.014004: (?^:(?x: pattern))


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^8: Recognizing 3 and 4 digit number
by kcott (Archbishop) on Jan 10, 2017 at 10:40 UTC

    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