Xref: utzoo comp.lang.perl:2324 comp.unix.admin:74 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl,comp.unix.admin Subject: Re: Looking for reaper skeleton Message-ID: <9454@jpl-devvax.JPL.NASA.GOV> Date: 11 Sep 90 01:33:37 GMT References: <1990Sep10.230742.9600@indetech.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 46 In article <1990Sep10.230742.9600@indetech.com> david@indetech.com (David Kuder) writes: : Or: Does anyone have a skeleton for a find equivalent written in Perl? : I think I could do what I want from that. This one will beat find in elapsed time on my machine, as long as you're primarily examining just the names. If you have to stat every file, it'll run a bit slower, but you can do away with the $nlink == 2 business. #!/usr/local/bin/perl &dodir('.'); sub dodir { local($dir,$nlink) = @_; local($dev,$ino,$mode); ($dev,$ino,$mode,$nlink) = stat('.') unless $nlink; # first time opendir(DIR,'.') || die "Can't open $dir"; local(@filenames) = readdir(DIR); closedir(DIR); if ($nlink == 2) { # this dir has no subdirectories for (@filenames) { next if $_ eq '.'; next if $_ eq '..'; print "$dir/$_\n"; } } else { # this dir has subdirectories for (@filenames) { next if $_ eq '.'; next if $_ eq '..'; $name = "$dir/$_"; print $name,"\n"; ($dev,$ino,$mode,$nlink) = lstat($_); next unless -d _; chdir $_ || die "Can't cd to $name"; &dodir($name,$nlink); chdir '..'; } } } Larry Wall lwall@jpl-devvax.jpl.nasa.gov