To a certain extent it depends on the size and number of the directories. You could use glob to grab all of the entries in a directory. i.e.
@files = glob("*.mp3");
That would get you a list of mp3s in the current directory. To transverse directories, you would want something like...
while (glob("*")) { if ( ! ( $_ =~ /^\./ ) ) { if ( -f $_ ) { #process files in this directory. } elsif ( -d $_ ) { #process a directory possibly with a recursive call } } }
By putting the above in a function and calling it recursively, you could actually scan down the entire tree. This of course can also be done with opendir etc. which is what you are doing I assume.
Most of the various possibilities for this scenario were fairly well fleshed out in another thread on perlmonks...
Can't seem to find it at the moment though, so someone else will have to give you the link.

In reply to Re: Scanning static directory tree for files by raflach
in thread Scanning static directory tree for files by shandor

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.