Here's what I think is a simple and easy to implement slide show in Perl...
For this exercise I would assume that you have some knowledge of the CGI module, and perhaps have touched the HTML::Template module before. And I also assume that the images you want to display is located under the htdocs/slideshow directory.
First create an HTML template for the slide show, which could be a simple HTML page with a table or two for the image and links. The images and links are injected into the template at run-time.
The perl script uses CGI to obtain the image name it is currently going to display. If the image name is undefined, then display the first image in the list.
The following script is a proof of concept I wrote for fun after lunch.
#!C:/Perl/bin/perl.exe -w
use strict;
use CGI;
my $q = new CGI;
my $q_image = $q->param('image');
my $image_url = "/albert"; # where the image is on web server
my @images = map { /([^\/]+)$/ }
<../htdocs$image_url/*.jpg>;
$q_image = $images[0] if ! defined $q_image;
my $html = do { local $/; <DATA> };
$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{<img src="$image_url/$q_image" alt="$q_image">};
}
sub prev_link {
return qq{<a href='/cgi-bin/p109.pl?image=}.get_prev_image().qq{'>
+PREV</a>};
}
sub next_link {
return qq{<a href='/cgi-bin/p109.pl?image=}.get_next_image().qq{'>
+NEXT</a>};
}
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__
<HTML>
<TITLE>Simple Image Slideshow CGI in Perl</TITLE>
<BODY>
<TABLE align=center>
<tr><td align=center>%%PREV%%</td><td align=center>%%NEXT%%</td></tr>
<tr><td colspan=2>%%IMAGE%%</td></tr>
</TABLE>
</BODY>
</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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.