in reply to Bug with weaken vs tie ???

In perl, a tie on arrays works by creating a temporary proxy object when you do an array subscript. When you later try to read or write to this object, it triggers the call to FETCH or STORE as appropriate. It is necessary to do it like that to allow code like this to Do The Right Thing:
sub p1 { print $_[0]} p1($tied_array[0]); # calls FETCH sub p2 { $_[0] = 0 } p2($tied_array[0]); # calls STORE
The net affect of this is that weaken($b[0]) is actually trying to weaken the temporary proxy object rather then the stored reference. (At least that's what I'm speculating; I've got a cold and it's too much effort to check right now)

Dave.

Replies are listed 'Best First'.
Re^2: Bug with weaken vs tie ???
by nothing94 (Initiate) on Feb 28, 2005 at 20:17 UTC
    "The net affect of this is that weaken($b[0]) is actually trying to weaken the temporary proxy object rather then the stored reference."

    This is actually what i thing (I think that weaken contains a bug) The actual code from Scalar::Util is :
    void weaken(sv) SV *sv CODE: sv_rvweaken(sv);
    I don't know Perl XS, but my guess is that if it is tied, it must fetch the internal value. This is my guess...