I wanted a web page that was super easy to maintain (lazy person that I am).
I basically wanted to drop new images in the 'images' folder and have them
accessible, sorted with newest images at the top of the table.  What I came
up with works but I had various questions about how to improve the coding
and how to improve on the web page appearance (I've worked with css files
before but not with CGI).  Also I cut and paste some of the code from
perlmonks and if anyone could give me a step by step description of what it
actually does - that would be cool.  Here goes:

*       When I say print start_html($title), that includes the body tag
correct?  How do I add the background image.  Below I did it by adding
another line but I guess my real question is - What is the syntax when
adding parameter values when using the shortcut notation?  This may also
answer the 'What's the syntax for adding a css link?' question.   
*       I see many different 'styles' of CGI coding, is the one displayed
below outdated, sufficient or recommended?  I've seen many sites with CGI
examples and everyone seems to do it different.  Obviously, I don't use the
shortcut notation (correct term?) entirely, as the table coding proved
tricky for me.  
*       See the 'map' code below.  Can you explain it step by step?  I know
what it does (sort an array by date) but not really how it does it.  
*       I'm using lstat ~and~ stat, is there a way to get the file
information in one step?

#!/usr/bin/perl -w
use CGI qw(:standard);
my $title  = "My Image Webpage";
my $subtitle = "Pictures";
my $dir = "../images/";
my $cols = 6;

#HTML----------
print header, start_html($title), h1($title);
print "<body background = ../grey_dots.gif>";
print br;
print <<_HEADER_;
<table border=1 cellpadding=2>
<tr>
  <th>Click on the file name:</th>
  <th>Date added:</th>
  <th colspan=4><br/></th>
</tr>
_HEADER_

#Open directory-----------
opendir(DIR,$dir) or die "error:cannot open $dir: $!";
my @files = readdir(DIR);
closedir(DIR);

#Sort files--------------
@files = map $_->[0],
         reverse sort { $a->[1] <=> $b->[1] }
         map { /^\./ ? () : [ $_, (lstat $_)[9] ] }
         @files;

my $a = 0;
my $b = 1;

#Print rows--------------
print "<tr>";
foreach (@files){
  if (/(^.*)\.jpg$/i) {
    my $desc = $1;
    if ($a == $cols/2) {
      print "</tr><tr>";
      $a = 0;
    }
    my $currImage = "$dir$_";
    print td($b.") ",a({-href=>$currImage},$desc));
    my @fileInfo = stat($currImage);
    my $fileDate = localtime($fileInfo[9]);
    print td($fileDate);
    $a++;
    $b++;
  }
}
print "</tr></table>";
print <<_PERL_;
<br/>
<a href="http://use.perl.org";>
<img src="http://use.perl.org/images/topics/useperl.gif"; width="100"
height="26" alt="All the Perl that's Practical to Extract and Report">
</a>
_PERL_
print end_html;

I know I should get the Metzler book, it's just that I only use CGI at home.
At work I'm stuck in ASP land.

Joel

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to