|
From: Dave C. <da...@da...> - 2001-11-16 19:30:34
|
On Fri, Nov 16, 2001 at 02:09:39PM -0500, Joseph F. Ryan (rya...@os...) wrote:
> I was trudging through search.pl today, when I noticed that we weren't
> using File::Find. I am pretty sure that File::Find has been part of the
> core since 5.004, so why not use it? At any rate, I changed this:
>
> ----------------------
> my @files = ('*.txt','*.html','*.dat', '*.src');
> my @search_files = get_files(@files);
> sub get_files {
> my @files = @_;
> chdir($basedir) or die "Can't chdir to $basedir: $!\n";
> my @found;
> foreach (@files) {
> $_ .= '/*' if -d "./$_" && !/\*/;
> }
> push @found, grep {-f $_ } glob($_) foreach @files;
> return @found;
> }
> ---------------------
>
> To this:
>
> ---------------------
> use vars qw($typelist);
> use File::Find;
> my @files = ('txt','html','dat', 'src');
> $typelist ='\.'.join('|\.',@files);
> my @search_files = find(\&wanted, $basedir);
> sub wanted
> {
> return if(/^\./);
> return unless(/$typelist/);
> stat $File::Find::name;
> return if -d _;
> return unless (-w _);
> }
> ----------------
You're right. There's no good reason for not using File::Find. But in
this case doesn't it change the behaviour of the script?
There are a couple of differences that I can see:
1/ The old version only searched the direcotries it was given, the new one
searches subdirectories too.
2/ In the old version, you could tell it to search files using wildcards
like 'doc*.txt', can you still do that in your version?
Feel free to implement your change, but please use the $emulate_matts_code
flag that we discussed a couple of days ago. When that flag is true then
we must emulate Matt's code _exactly_.
Dave...
--
.sig missing...
|