'lo

Stray Toaster mwk at stray-toaster.co.uk
Mon Aug 27 11:12:53 CDT 2001


On Mon, Aug 27, 2001 at 02:12:38PM +0100, Andrew Wilson wrote:
> On Mon, Aug 27, 2001 at 11:35:49AM +0100, barry wrote:
> Well, since you've asked ... I've had a look a photos.html
> 
> There is no real need for the subroutines unless you put them in some
> other file and import them.  Much better to use a templating system
> have a look at Template toolkit, it's excellent.

Another thing. This my be a bug bear of mine, but, godammit, get rid of
all that html in the code!! Either put it all in a template file (T::T,
HTML::Parser or one of their ilk) ot generate all the simple html via
the CGI object! (In case you didn't know, I *like* the CGI object).

I will refactor your (inc the bit by Andrew) later. Here is one I made
earlier. (It took me 20 minutes to do, with a woman standing over my
shoulder going 'you said you could knock that up in perl in 10 mins. Is
it done yet?' Coding under (spouse) pressure. Focuses the mind.)

#!/usr/bin/perl -w

use Apache;
use CGI qw(:standard);
use strict;

my $q = new CGI;
my $r = Apache->request;
(my $id = $r->path_info || 0) =~ s#^/##;

my $PATH = $r->document_root . "/taz/pics";
chdir $PATH or warn "can't CHDIR to $PATH: $!";

my $addy = "http://www.thefamilykerr.co.uk/taz/";

my @pics = <*.jpg>;
print $q->title("Taz - RIP");
print $q->h1("This was Taz, a very lovely (and loved) wee pussy cat");
my $next = $id + 4;
$next = 1 if ($next > @pics);

my $pic = $id ? $id : 1;
$pic = 1 if ($pic > @pics);
my $last_pic = $pic + 3;
for ($pic .. $last_pic) {
  my $display = $_;
  my $base = $addy . "pics/$display.jpg";
  my $img = qq{<img src = $base border=0 alt="He was a menace
indeed!">};
  print $img;
}

my $url = $id ? $addy . "taz.cgi/$next"
              : $addy . "taz.cgi/5";
print $q->a({ -href => $url}, "Next pics");


OK, so not the best, but the links are generated with the cgi object.
And the title, and the h1. See the pattern yet? Tables are easy too...
I have code somewhere which, uselessly, generated a dropdown menu
containing my exam results. But it is far nicer than having HTML mixed
with your perl. Urgg.

m.



More information about the Belfast-pm mailing list