This one resulted in all kinds of trouble, like infinite loops :D
This works like a charm on the other hand.
sub search_dir {
my ($dir) = @_;
print "Entered search_dir sub, working with directory => $dir \n";
my $dh; # handle
if ( !opendir ($dh, $dir)) {
warn "Unable to open $dir: $!\n";
return;
}
my @FILES = grep { $_ ne '.' && $_ ne '..' } readdir($dh);
foreach my $file (@FILES) {
my $path = "$dir/$file";
if ( -d $path ) {
print "Directory $path found\n";
search_dir ($path);
}
else {
print "File $path found\n";
}
}
closedir ($dh);
}
# END of search_dir sub
##############
Output:
...
File /csvfiles/2015/12/22.csv found
Directory /csvfiles/2015/10 found
Entered search_dir sub, working with directory => /csvfiles/2015/10
File /csvfiles/2015/10/16.csv found
File /csvfiles/2015/10/22.csv found
Directory /csvfiles/2015/11 found
Entered search_dir sub, working with directory => /csvfiles/2015/11
File /csvfiles/2015/11/16.csv found
File /csvfiles/2015/11/11.csv found
...