I went with "use Memoize;" and rewrote GetUser() slightly.
Since Memoize is interested in args passed and return values, I opted to
change the behavior of GetUser() to return a hash ref.
my $user;
$user = &inc::db::GetUser($id);
.....inc/db.pm...
use Memoize;
memoize('GetUser');
use DBI;
sub GetUser
{
my $id = @_;
my $ref;
...
return($ref);
}
Lots of calls to GetUser and the conversion of lots of hashes to hash refs,
but it was worth it. I don't have to manage a cache, but I get all the
benifits.
--Chuck
> -----Original Message-----
> From: Roger Grayson [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 15, 2002 5:42 PM
> To: Tomasi, Chuck
> Cc: [EMAIL PROTECTED]
> Subject: Re: Maintaining a Cache of Hash References
>
>
> Ronald J Kimball wrote:
>
> > On Tue, Jan 15, 2002 at 03:25:54PM -0600, Tomasi, Chuck wrote:
> >
> >>@UserCache; # Place to store data already seen
> >>sub GetUser
> >>{
> >> my ($id, $user)=@_; # record number and hash
> reference to populate
> >>
> > ^^^^^^^^^^^^^^^
> >
> >> if (defined($UserCache[$id])) {
> >>
> >> $user = $UserCache[$id];
>
> >> return(1);
> >>
> >
> > $user is lexically scoped to the body of the subroutine;
> this assignment
> > right before a return is pointless.
> >
> > I guess you also have a global variable named $user, which
> is what you
> > meant to set. Global variables should generally be
> avoided; have GetUser()
> > return the value instead.
> >
> > BTW, I don't see where the hashes come in. @UserCache is an array.
> >
> > Ronald
> >
> >
>
> Tomasi,
>
> Are you wanting to be able to call getuser() like:
> $rtn = getuser($is, \%hash_to_populate);
> ie. You want your return values in to be passed back through
> the hash reference you supply?
>
> If so you probobly want to say something like:
> %$user = %{$UserCache[$id]};
> in getuser().
> Roger
>
>
> --
> There are lies, there are damned lies, and there are the
> power point presentations you make up to explain your code.
>