At 04:18 PM 8/18/2003 -0700, John W. Krahn wrote:
> ... it looks like you want a closure instead.
>
>{ # limit scope of $bar
>my $bar = 100;
>sub foo { ++$bar }
>}
Thanks for the example. I quess I do want closure. I'm not clear on how
closure differs from memoizing. Regardless, this worked exactly as hoped:
$ cat zfoo.pm
use strict;
{ my $bar=100;
sub foo { return $bar++ }
}
$ cat foo.pl
#!/usr/bin/perl -wl
use strict;
use zfoo;
print foo();
print foo();
$bar is inaccessible, except through foo(), and remembered across repeated
invocations of foo().
Regards,
- Robert
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]