in reply to Re: subs && typeglobs
in thread subs && typeglobs
OK here are a couple of debugging print statements that show you why your code fails. The reason is you forget to add the directory separator as you recurse - as a result you do not search a valid path on your first recursion. See my code to see this happening - when you get a dir back from readdir it is called mydir not mydir/ as your code expects, add the / as shown and it will work.
my $Spath='c:/cluster1/'; opendir(H, "$Spath")|| die "Error:$!\n"; dir_search(*H,"$Spath"); sub dir_search{ local(*ROOT)=$_[0]; my $path=$_[1]; print "path $path\n"; my $cont; foreach $cont (sort readdir(ROOT)){ print " $path$cont\n"; next if $cont eq '.' or $cont eq '..'; next if -l "$path$cont"; if (-f "$path$cont"){ &log("$path$cont") if (-T "$path$cont" || -u "$path$cont"); } elsif (-d "$path$cont" && opendir(D,"$path$cont")) { dir_search(*D,"$path$cont"); # dir_search(*D,"$path$cont/"); <<-- this / is what you nee +d } } }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: subs && typeglobs
by s0ttle (Scribe) on Aug 04, 2001 at 15:41 UTC |