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:
- cgi-lib.pl has been superceded by CGI.pm, which is a modern standard. Your query parsing will be improved by using it.
- You should make use of the server's Basic Authentication, rather than handling it in your script. Consider using https for this.
- 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?
- 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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|