hsinclai has asked for the wisdom of the Perl Monks concerning the following question:
Here's a representative example from a larger script - I used the preprocess key in File::Find in an attempt to minimize matching operations and overhead inside of wanted's subroutine in the case of having to sift through many many files.
I must misunderstand what "preprocess" is for, but I am handing it the list it expects, I think..
So, does anyone know why the directory name gets returned in this case, and even better yet, a slick way to be able to specify file extensions from outside of "wanted" ?
Many thanks.. PS- I know it might be easier with File::Finder, and maybe other modules.. I was trying to stick with a standard module... many thanks..
Update: minor clarification of explanation
The correct files in the first level directory get returned, but two additional things happen:#!/usr/bin/perl -w use strict; use Cwd; use File::Find; my $filespec = '*.pl *.txt'; my $dir = $ARGV[0] || getcwd(); find( { wanted => \&find_function, preprocess => \&globber }, $dir ); sub find_function { print $File::Find::name . $/; } sub globber { ( glob "$filespec" ); }
- the first directory name (File::Find::dir) gets returned (I'm trying to get rid of that)
- File::Find seems to stop doing recursion
I must misunderstand what "preprocess" is for, but I am handing it the list it expects, I think..
So, does anyone know why the directory name gets returned in this case, and even better yet, a slick way to be able to specify file extensions from outside of "wanted" ?
Many thanks.. PS- I know it might be easier with File::Finder, and maybe other modules.. I was trying to stick with a standard module... many thanks..
Update: minor clarification of explanation
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Behavior of File::Find's preprocess and glob
by edoc (Chaplain) on Feb 04, 2005 at 01:07 UTC | |
by hsinclai (Deacon) on Feb 04, 2005 at 02:13 UTC | |
by edoc (Chaplain) on Feb 04, 2005 at 02:30 UTC | |
by hsinclai (Deacon) on Feb 04, 2005 at 02:43 UTC |
Back to
Seekers of Perl Wisdom