It fails on the assignment to $_ before the goto. The problem is there is no way to save off $_ and re-use it, making the central register, in perl, frozen/useless. Seems like a crack in the design -- I *rarely* got the message though I've reused that Vars code through many modules over a period of ~3 years.

As much as anything, not running into it is a reflection of perl-programming style -- i.e. if one rarely, if ever, uses constants hard-coded in the text of the 'for' loop (I almost always use for with an array or such -- even if it is an array of constants -- which doesn't hit this problem).

To answer the question of what happens if you call "for" in the target of the "goto", it overrides the global usage within the scope of the "for", then restores it. So the language *does* have "inherent" methods to do this, just, apparently, not explicit.

One reason (among others,) for splitting the code was to have most of the code parsed at compile time and leave as little parsing to runtime as possible. Compare that to the alternative where the entire "main sub" was in-lined in the "eval". Then, not only could I probably get around it by using "for" as a means to assign to "$_", (i.e. for ([$sav, et other vals]) { overriden value of "$_" active here; set to be ptr-to the indirect array }), but I wouldn't need to use it in the first place. *ARG* (hitting head against wall)...


In reply to Re^4: How to safely use $_ in a library function? by perl-diddler
in thread How to safely use $_ in a library function? by perl-diddler

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.