#!C:/Perl/bin/perl.exe -w use strict; use CGI; my $q = new CGI; my $q_image = $q->param('image'); my $image_url = "/images"; my @images = map { /([^\/]+)$/ } <../htdocs$image_url/*.jpg>; $q_image = $images[0] if ! defined $q_image; my $html = do { local $/; }; $html =~ s/%%([^%]*)%%/ if ($1 eq "IMAGE") { image_link() } elsif ($1 eq "PREV") { prev_link() } else { next_link() } /ge; print $q->header, $html; sub image_link { return qq{$q_image}; } sub prev_link { return qq{PREV}; } sub next_link { return qq{NEXT}; } sub get_prev_image { my %hash = map { $images[$_] => $_ } 0..$#images; return $images[$hash{$q_image}-1]; } sub get_next_image { my %hash = map { $images[$_] => $_ } 0..$#images; my $next = $hash{$q_image}+1; $next = 0 if $next > $#images; return $images[$next]; } __DATA__ Simple Image Slideshow CGI in Perl
%%PREV%%%%NEXT%%
%%IMAGE%%