Yes, providing quite broken 'tie' implementations can make any code blow up. q-:
Fixing your code so that it works and also demonstrates that things don't stop being tied shows that my code works fine with such things:
#!/usr/bin/perl -w use strict; # my $x = 1; tie my $x, 'Tie', 1; my $f = sub { $x }; print $f->(), "\n"; # => 1 { my $scope= tempSet( \$x, 2 ); print $f->(), "\n"; # => 2 } print $f->(), "\n"; # => 1 sub TempSet::DESTROY { shift(@_)->() } sub tempSet { my( $sv, $new )= @_; my $prior= $$sv; my $restore= bless sub { $$sv= $prior }, 'TempSet'; $$sv= $new; return $restore; } sub Tie::TIESCALAR { return bless \$_[1] => $_[0] } sub Tie::FETCH { return "${$_[0]} is still tied at line " . (caller()) +[2] } sub Tie::STORE { ( ${$_[0]} = $_[1] ) =~ s/ is still tied at line \d+$ +// }
which produces
1 is still tied at line 7 2 is still tied at line 10 1 is still tied at line 12
(Updated code to make tied-ness more apparent.)
(Yes, in constrast, local is implemented in a way that it temporarily hides the tied nature of the localized scalar.)
- tye
In reply to Re^3: Local for lexicals (KISS)
by tye
in thread Local for lexicals
by JadeNB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |