*handwaving at the File::Find answers* They're correct, but they don't answer your question.

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):

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; }
PS: I changed <> glob syntax to glob() syntax. Hope you don't mind. :)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.