in reply to Re: Re: Can you determine the number of References to a value?
in thread Can you determine the number of References to a value?

Yes, deleting your reference when the count goes to 1 makes sense in some situations. A more efficient way to accomplish this (and more general since it allows two or more different chunks of software to do the same trick to the same data) is called a "weak reference" which is available in Perl 5.6 and later.

A weak reference is just like an ordinary Perl reference except that it isn't included in the reference count of the thing referred to. This means that once all references to a particular piece of data are weak, the piece of data is freed and all the weak references are set to undef.

So you just have to check your weak references to make sure they haven't become undef before you use them. See WeakRef.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: Can you determine the number of References to a value?

Replies are listed 'Best First'.
Re: (tye)Re: Can you determine the number of References to a value?
by shotgunefx (Parson) on Sep 13, 2001 at 13:20 UTC
    Thanks tye++
    I hadn't seen this before. Looks like it'll do exactly what I want.

    If you don't mind me asking, what do you think of the constructs? I think they represent some things that occur fairly often in a nice way. There were present in a propriatery LISPish language I worked with. I liked them and thought they where handy.

    -Lee

    "To be civilized is to deny one's nature."