I'm trying cache a function to help speed it up. My function lives inside a
module, and is being called from a seperate script. It works if I do the
following.
foreach my $count (1..10) {
print "$count" . test("one") . "\n";
}
print "\n";
------ module sub routine --------
sub test {
my $param = shift;
my $cache_key = "param=$param";
if (exists $cache{$cache_key}) {
return $cache{$cache_key};
}
sleep 1;
$cache{$cache_key} = $param . "done"; # save the value
}
My problem with this is that I can't use strict, because I'm not declaring
%cache. If I do use strict, I'm forced to declare %cache, and when the sub
ends, the hash goes out of scope. So, my question is, can I create a
'static' hash for this fuctions that'll work with warnings and strict? I
know that there are modules for caching functions, but I don't have much
control of the environment and would rather not install extra modules.
Any help appreciated.
Thanks,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]