Files
devops/perl/Examples/Chap3/memoize
2025-09-17 16:08:16 +08:00

19 lines
247 B
Plaintext

###
### memoize
###
## Chapter 3 section 5
sub memoize {
my ($func) = @_;
my %cache;
my $stub = sub {
my $key = join ',', @_;
$cache{$key} = $func->(@_) unless exists $cache{$key};
return $cache{$key};
};
return $stub;
}