in reply to Re: Is it possible to localize the stat/lstat cache?
in thread Is it possible to localize the stat/lstat cache?
It turns out that the use of %Stat is very similar to what File::stat does under the covers, but my version only does those tests that I know I will need (saving a few cycles of processor time, most likely). In my case (since I know in advance which tests I need to worry about), this is sufficient.
I don't have an issue with building %Stat this way. It actually is (almost) the best solution to my need. I like to know alternatives, though, and realized that there was no stat equivalent to local $_; or local *FileHandle; in Perl. This seems like an oversight to me, as it should be a best practice to localize any global variables that you use in a function (especially one that is part of a module) so that you don't have to worry about side effects for the caller.
As for my comment above about %Stat being almost the best solution, I teaked my solution to drop the hash entirely (which avoids construction of the hash object, looking up the key in the hash, etc.). I ended up using one variable per test that I needed. Since these variables were declared outside the function and set right after the call to stat/lstat, they had a one-time construction cost plus the assignment per file and then multiple uses. In my specific case, this was the most efficient and simple solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Is it possible to localize the stat/lstat cache?
by bounsy (Acolyte) on Apr 20, 2015 at 12:40 UTC |