in reply to how can i hold temporary values in a recursive function
{ my %memo; sub rec_func { my $key=key_from_input(@_); unless (exists $memo{$key}) { $memo{$key}=calculate(@_); } return $memo{key}; } }
This should effectively cache complicated calculations based on the call-parameters...
(untested)
Of course you are free to decide what you are caching...
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how can i hold temporary values in a recursive function
by Corion (Patriarch) on Apr 18, 2010 at 16:51 UTC | |
by LanX (Saint) on Apr 18, 2010 at 16:59 UTC | |
by Corion (Patriarch) on Apr 18, 2010 at 17:04 UTC | |
by LanX (Saint) on Apr 18, 2010 at 17:14 UTC |