in reply to (MeowChow - tied local wierdness) Re3: Aliasing Variables
in thread Aliasing Variables

Yes, that matches what this node relies on, that local works by saving the old value and restoring it, exactly like assignments would. In your example, $obj is always pointing to the same SV.

However, using Alias, e.g. from the module:

@DYNAMIC = qw(m n o); { local @DYNAMIC; alias DYNAMIC => $tmp, PERM => $tmp; $DYNAMIC[2] = 'zzz'; # prints "abzzzd|abzzzd|abzzzd" print @$tmp, "|", @DYNAMIC, "|", @PERM, "\n"; } # prints "mno|pqr" print @DYNAMIC, "|", @PERM, "\n";
The Alias re-binds the symbol @DYNAMIC, essentially the same as *DYNAMIC=$tmp;. @DYNAMIC now aliases @$tmp.

But look at the local. It will restore the list @DYNAMIC, which means it will un-do this binding operation. If going out of scope does a STORE as you show, essentially @DYNAMIC=@saved;, it will overwrite the contents of @$tmp, as opposed to restoring the action of the *DYNAMIC=$tmp;. Follow me? He did not say local *DYNAMIC.

If local worked by pointing the symbol to a new SV, then there would be no need to FETCH/STORE, and the tie would not be preserved.

So there is still more to it than meets the eye.

—John