Re: Variable scoping, static variable

2003-03-29 Thread R. Joseph Newton
"R. Joseph Newton" wrote: > Sorry, the function I proposed [see bottom] did not properly enclose the > declaration, and thus would not have provided the protection I referred to.. Should > have been: > test_cache(); > sub test_cache { > my $cache = {}; > > &test("hello0",$cache); > &test(

Re: Variable scoping, static variable

2003-03-28 Thread R. Joseph Newton
"Shishir K. Singh" wrote: > Try using it like this > > - Hi Shishir, There is just one problem here, as demonstrated below, with the addition of a "brick-tosser" function. use strict; my $cache = {}; &test("hello0",$cache); # Note: better written as tes

Re: Variable scoping, static variable

2003-03-28 Thread John W. Krahn
Rob Anderson wrote: > > I'm trying cache a function to help speed it up. Have a look at the Memoize module at CPAN. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Variable scoping, static variable

2003-03-28 Thread Rob Dixon
Rob Anderson wrote: > Thanks but I don't see how this could work. I've tried using it, but to no > avail Hi Rob I can't think what could be wrong if you've copied Janek's code. I've written a simple subroutine with a persistent hash which simply counts the different strings it's called with and d

RE: Variable scoping, static variable

2003-03-28 Thread Shishir K. Singh
he->{$cache_key} = $param . "done"; # save the value print "does not exists\n"; } -- -Original Message- From: Rob Anderson [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2003 10:36 AM To: [EMAIL PROTECTED] Subject: Re: Variable scoping, static variable Thanks but I don't s

Re: Variable scoping, static variable

2003-03-28 Thread Rob Anderson
Thanks but I don't see how this could work. I've tried using it, but to no avail "Janek Schleicher" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Rob Anderson wrote at Fri, 28 Mar 2003 14:45:07 +: > > > -- module sub routine > > > > sub test { > > my $param =

Re: Variable scoping, static variable

2003-03-28 Thread Janek Schleicher
Rob Anderson wrote at Fri, 28 Mar 2003 14:45:07 +: > -- 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} = $