Your question is, why didn't this work?
The answer is that while(glob("*/")) has the glob working in its scalar context mode, which returns one directory element at a time. The problem is that when you pop into a subdirectory and pop back up again the iterator for the glob starts all over again at the beginning of the directory. I just noticed, you do this twice in the program. You wind up stepping on both iterators each subdirectory you go down.
Get the entire glob list out all at once into an array (which is localized to the sub) and then iterate over that. Try something like this (untested):
PS: I changed <> glob syntax to glob() syntax. Hope you don't mind. :)sub GetDirs { my ($Dir, $Posn) = @_; chdir $Dir if $Dir; my @list=glob("*/"); foreach (@list) { print "<div style=\"margin-left:$Posn\">$_</div>"; &GetDirs($_, $Posn + $Indent); } my @exts=glob("*.$ext"); foreach (@exts) { print "<div style=\"margin-left:$Posn\"><a href=\"editor.pl?Ac +tion=GetScript&File=$_\" target=\"$_\">$_</a><BR>"; } chdir "../" if $Dir; }
In reply to Re: file globbing in a nested while loop
by clintp
in thread file globbing in a nested while loop
by George_Sherston
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |