in reply to Recursive file search

File::Find and the other modules that Corion pointed out are, in my opinion, the easiest way to solve this problem. To answer your question about returning values from a recursive sub, since that could be generally useful for other things, you could do something like this:
sub loopDir { my @files; local ($dir) = @_; chdir $dir or die "Cannot chdir to $dir\n"; local(*DIR); opendir DIR, '.'; while ($f=readdir(DIR)) { next if $f =~ /^\./; push @files, $dir . '/' . $f if $f =~ /.*\.xml$/; if (-d $f) { # push the subdirectory's files onto @files push @files, &loopDir($f); } } closedir(DIR); chdir(".."); # return the list of files return @files; }

Replies are listed 'Best First'.
Re^2: Recursive file search
by merlyn (Sage) on Feb 20, 2005 at 04:24 UTC
      I'm not really sure wether i'm needing this feature or not. I know i should always prepare for the unexpected, but there should never be symlinks on these folders. I'll take the hint though and look for the direction of File::Find.