Hello all,
I want a variable to be memoized, that is, keep the variable available only
to the function and the value remembered across invocations. So far, I
have created two versions listed below, both of which "work." The first
version prints a warning message 'Variable "$bar" will not stay shared ...'
which I would like to avoid by coding The Right Way(TM). Also, I wonder if
the second version is modular enough so that it can be put in a module and
loaded.
Is there a better way to memoize?
Regards,
- Robert
------
#!/usr/bin/perl -wl
# version 1
use strict
sub foo {
my $bar=100;
sub bat {
$bar++;
return $bar;
}
return bat();
}
print foo();
print foo();
print foo();
----------
#!/usr/bin/perl -wl
# version 2
use strict
BEGIN {
my $bar=100;
sub foo {
$bar++;
return $bar;
}
}
print foo();
print foo();
print foo();
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]