'lo
Andrew Wilson
andrew at rivendale.net
Mon Aug 27 12:24:05 CDT 2001
On Mon, Aug 27, 2001 at 06:19:34PM +0100, Andrew Wilson wrote:
> #!/usr/bin/perl -w
>
> use Apache;
> use CGI qw(:standard);
> use strict;
>
> # Some constants
> my $num_pics = 4 # pictures per page
>
>
> my $q = new CGI;
> my $r = Apache->request;
> (my $page = $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>;
>
> # Work out which pictures to show and what page is next
> my $pages = int(@pics / $num_pics);
>
> # If client playing silly buggers (looking for a page that isn't there)
> $page = 0 if ($page > $pages);
>
> my $begin = $page * $num_pics;
> my $end = $begin + $num_pics -1;
> $end = ($end > @pics) ? @pics : $end;
> my $next = $page + 1;
>
> # if it's the last page, wrap around
> $next = ($next > $pages) ? 1 : $next;
>
>
> print $q->title("Taz - RIP");
> print $q->h1("This was Taz, a very lovely (and loved) wee pussy cat");
>
> for my $display ($begin .. $end) {
> my $base = $addy . "pics/$display.jpg";
> print qq{<img src = $base border=0 alt="He was a menace indeed!">};
> }
>
> my $url = $page ? $addy . "taz.cgi/$next"
> : $addy . "taz.cgi/$num_pics";
> print $q->a({ -href => $url}, "Next pics");
Just spotted a bug, next should reinitialise to 0 not 1 :-(
cheers
Andrew
More information about the Belfast-pm
mailing list