MeowChow has asked for the wisdom of the Perl Monks concerning the following question:

Is the following behaviour documented, explained, or implied anywhere in the documentation?
  
use strict; use Carp qw(carp); sub TIESCALAR { carp $/; bless \my $var => shift; } sub FETCH { carp $/; ${$_[0]} } sub STORE { carp $/; ${$_[0]} = $_[1]} $_ = 'one'; { my $foobar; local $_; tie $_ => 'main', 'two'; } # when above BLOCK is exited, $_ remains tied, and is reset to 'one' v +ia a STORE print "\ntied() of \$_ is ", tied $_, $/;
For that matter, is the converse (tie a variable, then localize it, and the local version will also be tied) explained anywhere?
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re (tilly) 1: Global effects of a local tie
by tilly (Archbishop) on Jul 23, 2001 at 05:07 UTC
    This is the same behaviour that I noticed at I think this is a tie bug. After that I found out from merlyn that tie and local are already known not to be friends...
Re: Global effects of a local tie
by John M. Dlugosz (Monsignor) on Jul 23, 2001 at 02:58 UTC
    Cross reference Re: (MeowChow - tied local wierdness) Re3: Aliasing Variables.

    If the docs in the Alias module are correct, that contradicts the way you are showing local implemented as

    # localize local $a= 42; # works like: my $saved= $a; $a= undef; $a= 42; # restore # works like $a= $saved;
    The docs in Alias imply that local will also restore a re-binding, e.g.
    local $x; *x= \$y; # point the scalar slot to alias $y #... # $x goes back to pointing to its own slot when restoring.
    If local worked by saving/restoring the slot, than this would be a natural consequence, but ties, blessing, etc. would not be preserved, and your sample code would not show what it does.

    —John