in reply to How to untie oneself?

Here is what I tried. I think its similar to what you've tried above. Its odd but convienient that after untie'ing you are left with a variable that has the same value as was last returned from FETCH. (At least on my perl v5.6.1). So you don't need to pass a reference to the variable in order to set it after the untie (here it is accessed through a closure).
use strict; use warnings; package MyTied; sub TIESCALAR { my ($class,$code) = @_; bless $code, $class; } sub FETCH { my $self = shift; print "Untie\n"; $self->(); } package main; my $var; tie $var, 'MyTied', sub { untie $var; 4 }; print "One\n"; print "$var\n"; print "Two\n"; print "$var\n"; print "Three\n"; print "$var\n"; OUTPUT: One Untie 4 Two 4 Three 4
Updated. several times.

Replies are listed 'Best First'.
Re: Re: How to untie oneself?
by Jenda (Abbot) on Jul 14, 2003 at 12:29 UTC

    Thanks. This works fine using Perl 5.6.1, but doesn't work under Perl 5.8. Under Perl 5.8 it prints:

    One Untie 4 Two Untie 4 Three Untie 4
    :-(((

    I tried to untie a different variable within the sub{} and that works, but untieing the variable whose FETCH handler is being processed simply doesn't work :-(

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature