/x only impacts how the regex is parsed. It can't impact how the string is parsed. \u impacts how the string is generated. The string has to be parsed and generated before the resulting string can be passed to the regex engine which then parses the string as a regex. And it is clear that /x can't impact the parsing of the string because the string has to be parsed before Perl can even see the /x.

If we fix your "bug", then we should also have to fix this to work:

"Y" =~ /\u(?x: y)/ or die "\\u and (?x: ) don't cooperate";

So this is a bit of a restatement of other replies, perhaps, but \u isn't a regex construct, so it isn't impacted by regex flags.

You'll also note other things that aren't impacted by /x:

/$foo bar[5]/x; # Not the same as /$foobar[5]/ /\ u2/x; # Not the same as /\u2/, obviously /\01 2/x; # Not the same as /\012/ /$hash{a Key}/x;# Not the same as /$hash{aKey}/

You can also tell that /x impacts regex parsing not string parsing because:

#!/usr/bin/perl -w my $x= " b c "; print for "abcd" =~ /$x/xg; # prints "bc"

And one other way to see that \u isn't a regex thingy:

print "($1)($2)\n" while "fFFggGGGG" =~ /([a-z]+)\U(\1*)/g; print "---\n"; print "($1)($2)\n" while "fFFggGGGG" =~ /([a-z]+)\U(\1*g)/g; __END__ Prints: (f)() (gg)() --- (gg)(G)

- tye        


In reply to Re: Regex bug? (/u not cooperating with /x) (string vs regex) by tye
in thread Regex bug? (/u not cooperating with /x) by mrpeabody

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.