use Memoize;
memoize('foo');
sub foo {
}
And if you want to be diligent do a benchmark to see if it is quicker.
Also, make sure that the functions have no side effects (io, setting global/package variables, etc)
-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
| [reply] |
Ahh now I see my problem:
My function receiving different parameters. For example I configured a database retrive function. As a parameter I receive the sql statement. Sometimes my application will call this retrive function with the same sqlstatement, only in this case I want to memorize it and return the "memorized" image without retriving the data again. Now I hope I am clear :) BTW thanks everyone for helping.
| [reply] |
that's fine. that is exactly what memoize does. If you called your memoized function with
func('select * from table1') the second time you ran it with that input, it would simply return the cached value from the first call.
And that is fine, if you don't care that the data may have changed in the db in the meantime.
-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
| [reply] |
Just like anywhere else? I don't see what's special. | [reply] |