> On Jul 9, 2015, at 8:27 AM, Nagy Tamas (TVI-GmbH) <tamas.n...@tvi-gmbh.de> > wrote: > > Hi, > > So I have a better version. But if it goes down in the recursion tree, at the > end it goes into infinite loop, > because there is no other dir inside the last dir in the tree. At this point > it has to step back. But instead > of stepping back it goes into infinite loop. Why? > > sub Traverse > { > if( opendir(DIR, $dir) ) { > my @files = readdir(DIR); > closedir(DIR); > foreach my $file (@files) { > # generate XML here > > $actualdir = $dir . "\\" ; > > next if (($file eq '.') || > ($file eq '..')); > > print $file; > if((-d $actualdir.$file) and > ($file !~ /^\.\.?$/) and ($file ne ".") and ($file ne "..")) { > # make dir > branch > > $newpath = > $actualdir.$file; > > > $writer->startTag("Folder", "Name" => $newpath); > > Traverse($newpath, $writer); > > $writer->endTag("Folder"); > } else { > # make file > branch > > $writer->emptyTag("Object", "Name" => $actualdir.$file); > > } > } > } > } > > Tamas
It is because you are calling the Traverse() subroutine with two arguments to recurse a directory tree, but you are not using the arguments. Each call to Traverse uses the global $dir variable as the root of the tree, so it will never terminate. You need a statement such as this near the top of your routine: my( $dir, $writer ) = @_; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/