jwlarson3rd has asked for the wisdom of the Perl Monks concerning the following question:

I need some help on writing a perl slide show that is activated when a user clicks on a image button. I have a script which displays images using information from a mysql table. when the user clicks on a images button I would like to activate a slide show with next prev and exit.this is the last thing that I have to accomplish. The script uses cgi.pm and is part of a large website. thanks john larson

Replies are listed 'Best First'.
Re: perl slide show
by Roger (Parson) on Dec 05, 2003 at 06:07 UTC
    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>
Re: perl slide show
by Mr. Muskrat (Canon) on Dec 05, 2003 at 05:16 UTC

    How about helping us to help you by giving us some more information?

    What have you tried so far? Descriptions are a great start (with as much detail as possible). The best way to ensure excellent responses is to include the source code that you are working on.

    What does not work? How did you attempt to fix it? Again be very descriptive and show any and/or all source code that you used to try and fix the problems.

    See also: How do I post a question effectively?.

Re: perl slide show
by Anonymous Monk on Dec 05, 2003 at 15:30 UTC
    So, the answers at clickable slide show perl were not helpful to you. You should at least be thoughtful enough to point out that you posted that node. What makes you think you would get different answers? Did you attempt any of the ideas pointed out to you at clickable slide show perl?