CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Stupid Comparisons



Dec 14, 2004, 1:27 AM

Post #1 of 3 (381 views)
Stupid Comparisons Can't Post

I am writing a script which will show one image at a time with a "previous" and "next" links. I have a subroutine that first takes in all of the image files in the directory and then counts them. I have it working so that if it's the first image in the directory, the "previous" link is disabled. Obviously I want the "next" link to be disabled when one is viewing the last image in the directory. Below is my code. The "previous" is working just as it should but no matter what I do, the "next" link is always there.

The following is in the 'required' modules file:

sub Get_Images {

opendir(CATEGORY, "./categories/$category");
@images = readdir (CATEGORY);

@images = grep { /[^.]/ } @images;

foreach $image (@images) {

The this is in the script itself:

$stay_under = $count;

if ($image > $stay_under) {
print "<a href=\"view_category.cgi?category=$category&image=$next\"><span class=subtitle>Next Image --></span></a>";
print "<a href=\"view_category.cgi?category=$category&image=$next\"><span class=subtitle>Next Image --></span></a>";

Ultimately I would want $stay_under to be $count minus one. I show all of the images as @images[$image] and since the images in the area start at "0", I want to subtract one from $count in order to get the "next" link to be inactive when viewing the last image in the directory.

*crawls back into hole*


Dec 15, 2004, 4:10 AM

Post #2 of 3 (342 views)
Re: [etheracide] Stupid Comparisons [In reply to] Can't Post

The if statement at the bottom has exactly the same statement in both blocks, which means that no matter what the condition statement returns, the print line is the same. Perhaps that's a typo?

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

Thaumaturge / Moderator

Dec 15, 2004, 8:57 AM

Post #3 of 3 (338 views)
Re: [etheracide] Stupid Comparisons [In reply to] Can't Post

In Reply To

foreach $image (@images) { 

That's just a complex way of writing

$count = @images;

Tho' you'd probably be better off with

$count = $#images;

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives