Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

syntax error

by eoin (Monk)
on Sep 21, 2003 at 19:28 UTC ( [id://293023]=perlquestion: print w/replies, xml ) Need Help??

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

Hey all, I have this picture album viewer script. Which is a part of a site that i am working on. I've posted a few questions on the project, the latest here.
Now i recon that I have, no wait had all the problems out of the script but, alas, it wasn't to be so.

When run the script(with the -c attrib) I get these errors from perl:
syntax error at albums.cgi line 102, near "else"
syntax error at albums.cgi line 110, near "elsif"
albums.cgi had compilation errors (#1)
    (F) The final summary message when a perl -c fails.

Uncaught exception from user code:
        syntax error at albums.cgi line 102, near "else"
syntax error at albums.cgi line 110, near "elsif"
albums.cgi had compilation errors.
Now I've searched the lines of code in question and the surrounding lines and I've failed to see the problem.
Heres the code in question(I've indicated the lines in question):
else { $row = qq(<td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; $ttlcounter++; } } } ###line 102;else { $nextpage_html = qq(<a href="http://eoinmurphy00.netfirms.com/cgi-b +in/albums.cgi?status=viewall&album=$album&page=$nextpage&user=$user"> +Next page</a>); } } ###110;elsif($page eq "1"){ my $nextpage = "2"; my $ttlcounter = "0"; my $tmpcounter = "0"; my $counter = "0"; my $img; my @images; for ($counter = "25", $counter =< "48", $counter++) { $img = "img$counter.jpg"; @images = push($img); }

If any of you could see the problem, I would greatly appricate help.
Oh and if you have any advice on how to improve the script that would also appricated greatly.

The rest of the code is inside
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; my $q = new CGI; my $status = $q->param('status'); my $album = $q->param('album') ; my $page = $q->param('page') ; my $img = $q->param('pic') ; my $user = $q->param('user') ; my @html; my $row; my $src; my $pic; my $html; my $viewersrc = "http://eoinmurphy00.netfirms.com/albums/$album/$img"; my $nextpage_html = qq(); if ($status eq "viewall"){ $html = viewall($page); } elsif ($status eq "viewer"){ $html = viewer($viewersrc, $user); } print qq(Content-type: text/html\n $html); sub viewall{ my $pic; my $dir = "../www/albums/$album"; my( $page )= @_; if ($page == undef) {$page=0;} else {} opendir DIR, "$dir" or die $!; my @images= grep /\.jpg/, readdir DIR; closedir DIR; if ($page == "0"){ my $nextpage = "1"; my $ttlcounter = "0"; my $tmpcounter = "0"; foreach $pic (@images) { $src = "http://eoinmurphy00.netfirms.com/albums/$album/$pic"; if ($ttlcounter <= "24") { if ($tmpcounter eq "3") { $tmpcounter = "0"; $row = qq(</tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; $ttlcounter++; } else { $row = qq(<td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; $ttlcounter++; } } } else { $nextpage_html = qq(<a href="http://eoinmurphy00.netfirms.com/cgi-b +in/albums.cgi?status=viewall&album=$album&page=$nextpage&user=$user"> +Next page</a>); } } elsif($page eq "1"){ my $nextpage = "2"; my $ttlcounter = "0"; my $tmpcounter = "0"; my $counter = "0"; my $img; my @images; for ($counter = "25", $counter =< "48", $counter++) { $img = "img$counter.jpg"; @images = push($img); } foreach $pic (@images) { $src = "http://eoinmurphy00.netfirms.com/albums/$album/$pic"; if ($ttlcounter =< "24") { if ($tmpcounter == "3") { $tmpcounter = "0"; $row = qq(</tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; $ttlcounter++; } else { $row = qq(<td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; $ttlcounter++; } } } else { $nextpage_html = qq(<a href="http://eoinmurphy00.netfirms.com/cgi-b +in/albums.cgi?status=viewall&album=$album&page=$nextpage&user=$user"> +Next page</a>); } my $album_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><p align="center"><font color="#FFFFFF" size="6" face="ITC Zapf Chancery"><strong><u>$album</u></strong +></font></p> <hr> <div align="center"><center><table border="0" cellpadding="0" cellspacing="0"> <tr> @html </table> </center></div><p align="right"><font color="#FFFFFF" face="Abbess"><em>$nextpage_html;</em> +</font>&nbsp;</p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html>); return $album_html } sub viewer{ my( $src, $user ) = @_; my @splitsrc = split(/\//, $src); my $currentpic = pop(@splitsrc); my @imgnmbr = ($currentpic =~ /\d+/g); my $nextimgnmbr = $imgnmbr[0]; my $previmgnmbr = $imgnmbr[0]; $nextimgnmbr++; $previmgnmbr--; my $nextpic = "pic$nextimgnmbr.jpg"; my $prevpic = "pic$previmgnmbr.jpg"; my $next_html = "http://eoinmurphy00.netfirms.com/cgi-bin/albums.cgi?s +tatus=viewer&album=$album&pic=$nextpic&user=$user"; my $previous_html = "http://eoinmurphy00.netfirms.com/cgi-bin/albums.c +gi?status=viewer&album=$album&pic=$prevpic&user=$user"; my $viewer_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="600"> <tr> <td colspan="2"><p align="center"><font color="#FFFFFF" size="7" face="ITC Zapf Chancery"><strong><u>$album</u> +</strong></font></p> </td> </tr> <tr> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u><a href="$previous +_html">Previous</a></u></font></p> </td> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u><a href="$next_htm +l">Next</a></u></font></p> </td> </tr> </table> </center></div><hr> <p><img src="$src"></p><p>&nbsp;</p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html> ); return $viewer_html }

Go raibh míle maith agat.
Thanks

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

Replies are listed 'Best First'.
Re: syntax error
by jeffa (Bishop) on Sep 21, 2003 at 19:45 UTC
    First off, advice on improving your script: start over! ;)

    Here is your syntax error, you have a structure like so:

    foreach (@stuff) { if ($boolean) { ... } } else { ... }
    That is invalid code. At this point, your script is almost (but not necessarily) beyond repair. I suggest that you sit down, design what you want to accomplish, and then use HTML::Template - this module will allow you you to take the HTML out of your Perl script so you can focus on logic. It takes a little time to understand HTML::Template, but it is time well invested -- as is designing. I also recommend you take the time to indent your code properly. If you don't know how to do that, then download Perl Tidy and run your code through it. Without proper indention, you run into problems like you have above. A lot of newbies say "I'll go back and indent it later." This never happens. Indent as you code and avoid mistakes like you have above. Best of luck. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: syntax error
by LazerRed (Pilgrim) on Sep 21, 2003 at 19:53 UTC
    You should check for mismatched {}'s I did some cut & paste action below, maybe it will help you see. I "think" you may have an extra } before your first else, and you may be missing one before your elsif. Just my best guess :-)
    if ($page == "0"){ foreach $pic (@images){ if ($ttlcounter <= "24"){ if ($tmpcounter eq "3"){ }else{ } } }else{ } } elsif($page eq "1"){ { } foreach $pic (@images){ if ($ttlcounter =< "24"){ if ($tmpcounter == "3"){ }else{ } } }else{ }
    LR

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://293023]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (None)
    As of 2024-04-25 01:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found