What about using the fact that the state declared variable will never be reinitialize for caching? Let's say the path, filename and filecontent will never change no matter how many calls are made to the function where it is needed. Then:
state $filename = File::Spec->catfile('path', 'path', 'filename.txt');
will cache the File::Spec call. Unfortunately this doesn't work:
state @content = read_file($filename);
# => Initialization of state variables in list context currently forbidden
In this case the working "cached versions" is more verbose:
state @content; @content = read_file($filename) if not @content;
The only problem of this persistent state is that it is persistent
use feature 'state'; # for caching 0 Comments More | Login | Reply /