summaryrefslogtreecommitdiff
path: root/lib/find.pl
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-06-18 07:00:42 +0000
committerCharles Bailey <bailey@genetics.upenn.edu>1996-06-18 07:00:42 +0000
commitdffa8cde9002476ae514bd0d995e9a1310014b8c (patch)
treeb3888d550cda2d8af4fc46624e5984d8637035be /lib/find.pl
parentb2391ea85a67736925638578f361d4f8a433ac07 (diff)
downloadperl-dffa8cde9002476ae514bd0d995e9a1310014b8c.tar.gz
Use newer File::Find to eliminate duplicate code
Diffstat (limited to 'lib/find.pl')
-rw-r--r--lib/find.pl80
1 files changed, 7 insertions, 73 deletions
diff --git a/lib/find.pl b/lib/find.pl
index 40e613e97e..29b83b082c 100644
--- a/lib/find.pl
+++ b/lib/find.pl
@@ -29,80 +29,14 @@
#
# Set the variable $dont_use_nlink if you're using AFS, since AFS cheats.
-sub find {
- chop($cwd = `pwd`);
- foreach $topdir (@_) {
- (($topdev,$topino,$topmode,$topnlink) = stat($topdir))
- || (warn("Can't stat $topdir: $!\n"), next);
- if (-d _) {
- if (chdir($topdir)) {
- ($dir,$_) = ($topdir,'.');
- $name = $topdir;
- &wanted;
- ($fixtopdir = $topdir) =~ s,/$,, ;
- &finddir($fixtopdir,$topnlink);
- }
- else {
- warn "Can't cd to $topdir: $!\n";
- }
- }
- else {
- unless (($dir,$_) = $topdir =~ m#^(.*/)(.*)$#) {
- ($dir,$_) = ('.', $topdir);
- }
- $name = $topdir;
- chdir $dir && &wanted;
- }
- chdir $cwd;
- }
-}
-
-sub finddir {
- local($dir,$nlink) = @_;
- local($dev,$ino,$mode,$subcount);
- local($name);
-
- # Get the list of files in the current directory.
-
- opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return);
- local(@filenames) = readdir(DIR);
- closedir(DIR);
+use File::Find ();
- if ($nlink == 2 && !$dont_use_nlink) { # This dir has no subdirectories.
- for (@filenames) {
- next if $_ eq '.';
- next if $_ eq '..';
- $name = "$dir/$_";
- $nlink = 0;
- &wanted;
- }
- }
- else { # This dir has subdirectories.
- $subcount = $nlink - 2;
- for (@filenames) {
- next if $_ eq '.';
- next if $_ eq '..';
- $nlink = $prune = 0;
- $name = "$dir/$_";
- &wanted;
- if ($subcount > 0 || $dont_use_nlink) { # Seen all the subdirs?
+*name = *File::Find::name;
+*prune = *File::Find::prune;
+*dir = *File::Find::dir;
- # Get link count and check for directoriness.
-
- ($dev,$ino,$mode,$nlink) = lstat($_) unless $nlink;
-
- if (-d _) {
-
- # It really is a directory, so do it recursively.
-
- if (!$prune && chdir $_) {
- &finddir($name,$nlink);
- chdir '..';
- }
- --$subcount;
- }
- }
- }
- }
+sub find {
+ &File::Find::find(\&wanted, @_);
}
+
1;