Yes, this appears to be a scoping problem. I'm not fully versed in what is going on, but based on similar issues I've seen in the past, by safest suggestion is to turn %mv into a global (our) var, localize it on entry to domatch, and then return a reference to a copy of it like return { %mv }.

I think what's happening is that because the regular expression doesn't change, it only gets compiled once and thus the %mv within those ?{} blocks gets bound to the lexical %mv that's created the first time domatch gets called. To see if I'm right, try saving the reference to the return value from domatch only the first time it's called but printing the contents of it after each iteration.

If I'm right, this is somehow related to the "won't stay shared" warning though I admit I don't have a solid grasp on why.


In reply to Re: regex eval capture weirdness by Errto
in thread regex eval capture weirdness by bytex64

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.