Perl Recurse through Directory -
so i'm trying go through directory , perform action on of files, in case, sub searchforerrors. sub works. have far is:
sub proccessfiles{ $path = $argv[2]; opendir(dir, $path) or die "unable open $path: $!"; @files = readdir(dir); @files = map{$path . '/' . $_ } @files; closedir(dir); (@files){ if(-d $_){ process_files($_); } else{ searchforerrors; } } } proccessfiles($path);
any help/suggestions great. , again, i'm new perl, more explanation better. thank you!
you should use file::find
module instead of trying reinvent wheel:
use strict; use warnings; use file::find; @files; $start_dir = "somedir"; # top level dir search find( sub { push @files, $file::find::name unless -d; }, $start_dir ); $file (@files) { searchforerrors($file); }
a problem current code including .
, ..
directories in recursive search, no doubt cause deep recursion
errors.
Comments
Post a Comment