First, I'd like to warn you to look above this snippet for security problems. I don't see anything here to say you run this in taint mode, or use CGI; for query parsing. You may be doing that already, which is good.

File::Find is a great help in recursing through directory trees. It will do the right thing with symlinks, and can handle all the file tests you need to do.

If you have many, you may want to consider a Schwartzian Transform for a case insensitive sort.

Update: Re your reply:

  1. cgi-lib.pl has been superceded by CGI.pm, which is a modern standard. Your query parsing will be improved by using it.
  2. You should make use of the server's Basic Authentication, rather than handling it in your script. Consider using https for this.
  3. The -wT options on the shebang line will turn on warnings and taint mode. Taint checking forces you to examine user input for damaging stuff. In this case, can a user send '../../../../*' and wipe clean your mounted filesystems?
  4. use strict; as always. It will frustrate you at first, but it is truly worth it. It prevents some sneaky bugs and spots many typos.
'perldoc perlsec' is a good read. I also regard the article phrack 55.7 as required reading. It is a real eye-opener.

After Compline,
Zaxo


In reply to Re: how can i also show sub folders by Zaxo
in thread how can i also show sub folders by Anonymous Monk

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.