When I wrote this post last night I originally intended to add comments to the compiled regular expressions using extended syntax. However, when I did that the code suddenly started generating a "Use of uninitialized value in concatenation (.) or string" warning in the expression and I couldn't see why. I can now see what the problem is but I'm puzzled as to why it is happening. If I put a variable name in the comment the warning appeared and I had to escape the $ sigil to make the warning go away, which is a bit worrying in what is supposed to be of no significance to the compiler. Here are examples of the regex and what happens in each case.

Original regular expression, no warning generated

$rxNumberGrps = qr {(?x) \D* (\d+) (?=,|\)) (?{$deCommafied .= $^N}) (?: (??{$rxNumberGrps}) | \)\z ) };

With offending comment added, warning generated

$rxNumberGrps = qr {(?x) \D* (\d+) (?=,|\)) # append capture to $deCommafied (?{$deCommafied .= $^N}) (?: (??{$rxNumberGrps}) | \)\z ) };

escape sigil, no warning generated

$rxNumberGrps = qr {(?x) \D* (\d+) (?=,|\)) # append capture to \$deCommafied (?{$deCommafied .= $^N}) (?: (??{$rxNumberGrps}) | \)\z ) };

use (?# ... ) style comment, no warning generated

$rxNumberGrps = qr {(?x) \D* (\d+) (?=,|\)) (?# append capture to $deCommafied) (?{$deCommafied .= $^N}) (?: (??{$rxNumberGrps}) | \)\z ) };

Other than the warning being generated, there was no effect on the running of the script and the same output was produced each run. It looks to me like the extended syntax comments aren't stopping the interpolation of variables in some way or another. Is this some sort of bug or am I missing something?

Cheers,

JohnGG


In reply to A variable name in a regex comment triggers a warning by johngg

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.