in reply to Implementing a Data Cache

I did it this way - same effect as saurog's. I believe the problem was you were returning a copy of the array from access_cache - I just changed that to a reference and used that reference
#!/usr/bin/perl -w use strict; use diagnostics; { my $cache = [Foo->new]; sub access_cache { return \@$cache; } } foreach (@{&access_cache()}) { print STDERR "before: ", ref($_), "\n"; print STDERR "object: ", $_, "\n";; print STDERR "after: ", ref($_), "\n\n"; } foreach (@{&access_cache()}) { print STDERR "before: ", ref($_), "\n"; print STDERR "object: ", $_, "\n"; print STDERR "after: ", ref($_), "\n"; } package Foo; sub new {bless [], $_[0]}; use overload '""' => sub {$_[0] = Bar->new; return $_[0]->[0]}; package Bar; sub new {bless ['barbar'], $_[0]}; use overload '""' => sub {return $_[0]->[0]};

Replies are listed 'Best First'.
Re: Re: Implementing a Data Cache
by sauoq (Abbot) on Jul 09, 2003 at 22:18 UTC
    return \@$cache;

    It's a nit, but that's unnecessarily messy. In this case, just return $cache; rather than taking a reference after dereferencing.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Implementing a Data Cache
by zealot (Sexton) on Jul 09, 2003 at 18:41 UTC
    Thanks for the help! It is working correctly now with these changes.