Another note to take is that <*/> isn't a very clean way to find subdirectories; a better way is to use the -d filetest operator. I would propose something akin to this (untested):
. . local $_; # always a good habit unless you know why don't want it chdir $Dir; opendir DIR, '.'; my (@dirs, @files); for (readdir DIR) { next if /^\.\.?$/; # we don't want to catch the . and .. entries push @dirs, $_ if -d and not -l; # only non-symlink dirs please push @files, $_ if -f and /\.ext$/; # -f because it could be a dir +ectory or other non-file called "something.$ext" } closedir DIR; . .
Afterwards you have the directories and desired files in the appropriate arrays. A note for completeness' sake is that using readdir() like this can be noticably slower than a glob when directories contain a lot of files (as in several thousand). However unless you're running a heavy load application and this piece of code is among your script's bottlenecks, it won't make a difference while it is more maintainable and less prone to errors IMHO.

But anyway - this was just an excercise, for real work, you should indeed rely on File::Find. :)

In reply to Re: file globbing in a nested while loop by Aristotle
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.