Here's how I'd do this. Do note the use of CGI.pm (this beast is now big enough to use it, and the HTML shortcuts will come in handy) as well as strict. I can't stress enough how useful strict is. If you havn't already, please do read all of use strict warnings and diagnostics or die.

The generalization that directories do not contain periods is not particularly true. The true way to test is with the -d file test operator.

Also, CGI::Carp will spew error messages to the browser, like you were looking for.

Anyways, here's how I'd do it:

#!/usr/bin/perl -w use strict; use CGI qw/:standard escape/; use CGI::Carp; my @noshow = (".", "..", __FILE__); my (@directories,@files); opendir(DIR,"./") or die "Couldn't open directory: $!"; for my $entry (sort readdir(DIR)) { next if grep {$_ eq $entry} @noshow; if (-d $entry) { push @directories, $entry; } else { push @files, $entry; } } closedir(DIR); print header, start_html, div({-style=>"border: solid 1 #003366; background: #F1F1F1; text-align: left; padding: 4px; width: 200px;"}, map {a({-style => "font-size: 13px; color: #000000;", -href => "./read_file.cgi?file=".escape($_)},$_) .br} @files), end_html;

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


In reply to Re: more with directory contents by Chmrr
in thread more with directory contents by einerwitzen

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.