Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re: Class DBI and reference counting

by chromatic (Archbishop)
on Jan 10, 2006 at 18:07 UTC ( [id://522346]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Class DBI and reference counting

If you're using a modern enough Perl (5.6.1 or later, I believe), use Scalar::Util's weaken() function to create weak references in your cache. The documentation for the function shows a similar application.

Replies are listed 'Best First'.
Re^2: Class DBI and reference counting
by Nomis52 (Friar) on Jan 10, 2006 at 18:43 UTC
    I acutally tried weaken before posting:
    sub flagged2 { my $self =shift ; unless(defined($self->{f})) { my @bs = $self->bs( flag => 1 ) ; $self->{f} = weaken(shift @bs) ; } return $self->{f} ; }
    The problem is on the first call to the function it works as expected, but the second time it's called the object has already gone out of scope and been destroyed resulting in an undefined value returned.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://522346]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.