|
From: Joseph F. R. <rya...@os...> - 2001-11-16 19:12:00
|
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 _);
}
----------------
|