in reply to Referencing localized variables, and typeglobs

With reference only to the first part of your OPed question, I agree with Laurent_R's explanations here and here.

Here's another way to think about the issue that might offer some confidence and comfort, for all it's long-windedness. (I don't doubt that you understand all this perfectly well, but perhaps someone else may benefit from this blatheration.) With reference to the OPed code:

Looking at the differing reference addresses of the various storage locations created by your original code example may also be convincing:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "print 'perl version: ', $]; ;; our %h; ;; my $x = do { local %h=(a=>'3'); \%h }; my $y = do { local %h=(b=>'5'); \%h }; ;; print 'ref. addr. of %h: ', \%h; dd 'contents of %h: ', \%h; ;; print 'ref. addr. of $x: ', $x; dd 'contents of $x: ', $x; ;; print 'ref. addr. of $y: ', $y; dd 'contents of $y: ', $y; " perl version: 5.008009 ref. addr. of %h: HASH(0x2c068a4) ("contents of %h: ", {}) ref. addr. of $x: HASH(0x14b5fa4) ("contents of \$x: ", { a => 3 }) ref. addr. of $y: HASH(0x14b60dc) ("contents of \$y: ", { b => 5 })
(Note that this example was run under Perl 5.8.9.)

... I'm wondering if it's "safe" ...

Yes, Dr. Szell, it's perfectly safe.


Give a man a fish:  <%-{-{-{-<