in reply to Re: File::find preprocess problem
in thread File::find preprocess problem
I've played a bit with this option before. When File::Find enters a new directory, it does a readdir(). The output of that readdir() is what goes into the preprocess routine. What you return is a) filtered version of that or perhaps even b) a sorted version of that. If you take a directory name out of this list, find() will not follow down that path (useful for pruning off a directory branch).
I'm not sure that using the preprocess option will make any significant difference in performance in this case. Depends upon how many files are in the /advanced/ directories.
As a trick, there is a special variable _, (note not $_). When a file test is done, this causes a stat(), in this case using the _ will cause the file test info from the -f test to be re-used. This will make a performance difference - stat() is not a quick operation. There are some "yeah but's concerning various types of links - I forget the details right now, but usually this is not an issue.
Didn't test this, but I think this will work...if I got my unless logic right.
Update: Ooops, looked again it appears the the below should be changed, OP wants to process .log files and follow all directories that aren't "advanced".
sub preprocess { my @to_return; foreach (@_) { #don't follow down advanced directory paths #Do call wanted() on .log files (and any directory not #underneath an "advanced" one push @to_return, $_ if ( ( -f and /\.log$/ ) or !( -d _ and /advanced/) ); } return @to_return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: File::find preprocess problem
by zentara (Cardinal) on Apr 27, 2012 at 10:05 UTC | |
by Marshall (Canon) on Apr 27, 2012 at 11:51 UTC | |
by Anonymous Monk on Apr 27, 2012 at 14:16 UTC | |
by zentara (Cardinal) on Apr 27, 2012 at 14:48 UTC | |
by Anonymous Monk on Apr 28, 2012 at 03:07 UTC | |
by Anonymous Monk on Apr 28, 2012 at 04:07 UTC |