Thanks for the reply! My main concern is that I haven't yet found a description of the behavior in the perldocs or (so far) elsewhere.

So while you are right that the behavior does seem logical, there is another possible interpretation of the code: One might expect that after the effects of the local are over, $x and $y could refer back to the original %h, instead of some anonymous hashes. I'm not saying this interpretation is better or worse than the actual behavior, just that it'd be nice if it were documented.

Another concern is that perlsub says "This operator works by saving the current values of those variables in its argument list on a hidden stack and restoring them upon exiting the block, subroutine, or eval." - So the values are saved on a stack and presumably the temporary value is popped back off when the scope exits. Without some reassurance from the docs, one might worry that the temporary variables might somehow "go away" when the scope exits (e.g. is this stack refcounted?) and a reference to such a value might become invalid (however unreasonable or not the worry might be).


In reply to Re^2: Referencing localized variables, and typeglobs by haukex
in thread Referencing localized variables, and typeglobs by haukex

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.