I've revisited this script and made some enhancements and cleaned it up so it is less obfuscated. (-:
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; $|=1; my $columns = param('c') || 4; opendir(DIR, ".") || die "cannot open dir: $!"; foreach (sort readdir(DIR)) { next if /~\z/ || $_ eq "ls.cgi" || $_ eq "." || $_ eq ".."; push @{ (-d) ? $_[0] : $_[1] }, (-d) ? b(a({href=>"$_"},"[ $_ ]")) : a({href=>"$_"},"$_"); } closedir DIR; # Combine dirs and files $_[3] = [ @{$_[0]}, @{$_[1]} ]; print header, start_html('Directory Listing'), h3('Directory Listing'), b("Dir Count: ".@{$_[0]}), b(", File Count: ".@{$_[1]}), table({-border=>0,-cellpadding=>5,-cellspacing=>5}, map Tr($_), grep { length($_) > 0 } map td([ splice @{$_[3]},0,$columns ]), @{$_[3]} ), end_html; __END__

Most notably I've taken another look at Aristotle's code and replaced the cute splice with array refs which turns out to be useful in the output section. E.g. I've added a directory count and a file count.

The other noticable part is that I've removed the 0 .. (@_ / $columns) and inserted a grep to eliminate extra list elements that cause extra TR elements (the initial reason I put that in there in the first place).

And, yes, I cleaned up the exclusion logic to use eq, etc.

Enjoy!

Update: Yes, the grep is a hack, for a full treatize on this issue click here.

--
hiseldl
What time is it? It's Camel Time!


In reply to Re: Ordered Directory Listing CGI by hiseldl
in thread Ordered Directory Listing CGI by hiseldl

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.