Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
anyway, the function, called traversePath, is passed a root pathname, and it's supposed to call another instance of itself for each subdirectory and pass it $npath, but when it calls the new instance, it seems to use the same $path as the instance that called it, which basically puts it into an infinite loop, rechecking the root dir over and over again...
heres the sub:
and heres the output when initially passed the path "f:/" (it falls into an infinite loop and repeats this endlessly):sub traversePath($path) { ##DEBUG## print "\nDEBUG:traversing path '$path'\n"; ##DEBUG## # will contain combined filesize of all files in pwd $totalSize = 0; # convert any backslashes to fwdslashes $path =~ s/\\/\//g; # open up the current dir opendir(PATH,$path); # check for trailing slash and remove if found if(substr($path,-1,1) eq "/") {chop($path)} #read files & subdirs into @subdirs @subdirs = readdir(PATH); closedir(PATH); # loop through them all foreach $subdir (@subdirs) { # construct full pathname to current subdir or file $npath = $path."/".$subdir; # not a dir, just a file, perform a function # which returns the byte size of said file if(! -d $npath) { $totalSize += writeFile($npath); } # is a subdir else { # dont mess with cwd or parent dir if($npath ne "." && $npath ne "..") { ##DEBUG## print "\nDEBUG:npath='$npath'\n"; ##DEBUG## # call new instance of self and pass as param # to other function which records total bytesize # of directory writeDir($npath, traversePath($npath) ); } } } # return bytesize of any files found in current dir return $totalSize; }
does anyone see anything i'm not seeing? any help i would greatly appreciate.DEBUG:traversing path 'f:' DEBUG:npath='f:/winnt'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: recursive path function falls into infinite loop
by Zaxo (Archbishop) on Nov 25, 2004 at 04:59 UTC | |
by Anonymous Monk on Nov 25, 2004 at 05:36 UTC | |
|
Re: recursive path function falls into infinite loop
by tachyon (Chancellor) on Nov 25, 2004 at 07:05 UTC | |
|
Re: recursive path function falls into infinite loop
by diotalevi (Canon) on Nov 25, 2004 at 05:48 UTC | |
by merlyn (Sage) on Nov 25, 2004 at 13:20 UTC | |
|
Re: recursive path function falls into infinite loop
by Thilosophy (Curate) on Nov 25, 2004 at 08:30 UTC | |
|
Re: recursive path function falls into infinite loop
by TedPride (Priest) on Nov 25, 2004 at 15:22 UTC | |
by merlyn (Sage) on Nov 25, 2004 at 15:47 UTC | |
|
Re: recursive path function falls into infinite loop
by steves (Curate) on Nov 25, 2004 at 13:28 UTC |