Perl 5.16, I'm trying to count digits in a scalar
DB<34> x $_ 0 '1223w3433.45+34'
..the expression inexpliquably drops the 1st digit (the 1) the first time I evaluate the regex:

DB<30> x /\d\D*/g 0 2 1 2 2 '3w' 3 3 4 4 5 3 6 3. 7 4 8 '5+' 9 3 10 4

But after that first time, the 1 is back? I changed nothing- just examined it again...

DB<31> x /\d\D*/g 0 1 1 2 2 2 3 '3w' 4 3 5 4 6 3 7 3. 8 4 9 '5+' 10 3 11 4 DB<32> x /\d\D*/g 0 1 1 2 2 2 3 '3w' 4 3 5 4 6 3 7 3. 8 4 9 '5+' 10 3 11 4 DB<33> x /\d\D*/g 0 1 1 2 2 2 3 '3w' 4 3 5 4 6 3 7 3. 8 4 9 '5+' 10 3 11 4 DB<34> x $_ 0 '1223w3433.45+34'
I changed the dot and plus to non-interpolated chars like W and Z, and it finds all the digits consistently. So I'm thinking its some kind of interpolation thing BUT, why would it interpolate differently on trial 1, than on subsequent trials? And if it IS some interpolation thing, why remove the first digit when the interpolated chars are in the middle?

Its perplexing! I also tried /{expression}/ and /\Qexpression\E/, and using $x instead of $_ - none worked.

How can I turn off interpolation, assuming that's the issue? I suppose one *fix* is to simply do the same evaluation 2X, but I can't imagine that's what Larry would suggest!

TYVM


In reply to Some odd ambiguity in this regex by misterperl

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.