in reply to How to change referent of lexical reference?

You can modify any arguments (references or ordinary scalars) passed to a sub by editing them inplace in @_ (as opposed to making a copy with shift inside the sub). I can't tell from your description if this is possible in your case, but it's a thought:
my $foo = \"foo"; my $bar = \"bar"; print "$$foo\n"; change_ref($foo); print "$$foo\n"; sub change_ref { $_[0] = $bar; } __OUTPUT__ foo bar
I would assume there's a corresponding way to do it in XS too, but I'm not the one to ask about that.

blokhead

Replies are listed 'Best First'.
Re: Re: How to change referent of lexical reference?
by autarch (Hermit) on Sep 21, 2003 at 20:58 UTC
    Hmm, I just tried that but it didn't work. The STORABLE_thaw() method gets called from Storable's XS code, which may explain the problem.

    I think that Storable calls STORABLE_thaw with a blessed reference of the appropriate type (in my case a hash ref) and then looks directly at the _referenced_ data after calling the method, as opposed to looking at the reference itself.

    So I need a way to switch the referent out from under the reference.