Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Program can't work on website; please examine code

by Anonymous Monk
on Nov 30, 2001 at 01:55 UTC ( #128474=perlquestion: print w/replies, xml ) Need Help??

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

I had this darn app. working just last week. Now I can't get it to work on my web site. I believe all of the code is correct. If one of you could just take a small peek at it, I would be most grateful.
#!/usr/bin/perl use strict; # Loads the CGI Module use CGI; # creates a new CGI object my $page = new CGI; # Grab a named CGI parameter my $value = $page->param("Comic"); ##########declare the names of the files for the loop my @Comm = ('Images/Le_Comic.jpg', 'Images/Le_Comic2.jpg', 'Images/Le_ +Comic3.jpg', 'Images/Le_Comic4.jpg', 'Images/Le_Comic5.jpg', 'Images/Le_Comic6.jpg' +, 'Images/Le_Comic7.jpg', 'Images/Le_Comic8.jpg', 'Images/Le_Comic9.jpg' +, 'Images/Le_Comic10.jpg', 'Images/Le_Comic11.jpg', 'Images/Le_Comic12.j +pg', 'Images/Thanksgiving_Comic.jpg'); ########## #Open up the comments file open (FILE, '../Comment.txt') or die "The file could not be opened.\n" +; #Save the contents of the FILE handle to an array my @Comment = <FILE>; #Close the FILE close(FILE); my ('$i','$Como','$Number'); #do a "for" loop to make it choose the quote for ($i=0; $i<=@Comment; $i++) { #Do an "if" loop to go through and save the right quote if ($value eq $Comm[$i]) { $Como = $Comment[$i]; #Save the number of the quote to a variable for the title $Number = $i + 1; } } ## Then: # This will print a standard HTML header print $page->header; print "<HTML><HEAD>\n"; print <<ENDMETA; <META NAME="GENERATOR" CONTENT="Adobe PageMill 3.0 Win"> <TITLE>Animetion Station &gt; Webcomic &gt; Comic &#35;$Number</titl +e> <LINK REL="stylesheet" HREF="../Style.css" TYPE="text/css"> ENDMETA print "</head><BODY>\n"; print <<ENDHTML; <P><CENTER><DIV STYLE="background-color: #0099FF; font-family: Comic S +ans MS; font-size: 20px; width: 200px; color: white;">Web Comics</div></center></p> <P><TABLE WIDTH="757" BORDER="0" CELLSPACING="1" CELLPADDING="0" HEIGH +T="294"> <TR> <TD WIDTH="14%" VALIGN="TOP" ALIGN="CENTER" HEIGHT="293"> <div class="Standard"> <P><CENTER><A HREF="../index.htm">[Home]</a> <HR> <A HREF="../Gallery.shtml">[Gallery]</a> <HR> <A HREF="../Manga.shtml">[Manga]</a> <HR> <A HREF="../Video_Review.shtml">[Video Reviews]</a> <HR> <A HREF="../Links.shtml">[Links]</a> <HR> <A HREF="../Web_Comic.shtml">[Web Comic]</a></center></td> <TD VALIGN="TOP" WIDTH="270" HEIGHT="131"> </div> </td> <TD WIDTH="86%" VALIGN="TOP" BGCOLOR="#3366ff"> <P><CENTER><IMG SRC="../$value"></center></p> <br> <p>$Como</p> <CENTER> <DIV STYLE="font-family: Times New Roman,Times; color: white; widt +h: 350px; background-color: gray; text-align: center;"> <P><B><U>Comics</u></b></p> <P> <A HREF="Testy.cgi?Comic=Images%2fLe_Comic.jpg">Comic #1</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic2.jpg">Comic #2</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic3.jpg">Comic #3</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic4.jpg">Comic #4</a> | + <A HREF="Testy.cgi?Comic=Images%2fLe_Comic5.jpg">Comic #5</a><br +> <A HREF="Testy.cgi?Comic=Images%2fLe_Comic6.jpg">Comic #6</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic7.jpg">Comic #7</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic8.jpg">Comic #8</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic9.jpg">Comic #9</a> | <A HREF="Testy.cgi?Comic=Images%2fLe_Comic10.jpg">Comic #10</a>< +br> <A HREF="Testy.cgi?Comic=Images%2fLe_Comic11.jpg">Comic #11</a> </p> <p> <center><u><font type="Comic Sans MS" size="4">Special Comic</fon +t><u></center><br> <A href="Testy.cgi?Comic=Images%2fThanksgiving_Comic.jpg">Thanksg +iving Comic</a> </p> </div> </center> </td> </tr> </table> ENDHTML print "</body></html>\n";

Edit kudra, 2001-12-02 Changed title

Replies are listed 'Best First'.
(Ovid) Re: Stupid Program!
by Ovid (Cardinal) on Nov 30, 2001 at 03:54 UTC

    Ignoring the HERE doc, try this:

    #!/usr/bin/perl use strict; use CGI; my $page = new CGI; my $value = $page->param("Comic"); ##########declare the names of the files for the loop my @Comm = qw( Images/Le_Comic.jpg Images/Le_Comic2.jpg Images/Le_Comic3.jpg Images/Le_Comic4.jpg Images/Le_Comic5.jpg Images/Le_Comic6.jpg Images/Le_Comic7.jpg Images/Le_Comic8.jpg Images/Le_Comic9.jpg Images/Le_Comic10.jpg Images/Le_Comic11.jpg Images/Le_Comic12.jpg Images/Thanksgiving_Comic.jpg ); #Open up the comments file my $file = '../comment.txt'; open FILE, "< $file" or die "Cannot open $file for reading"; my @Comment = <FILE>; close(FILE); my ( $Como, $Number); #do a "for" loop to make it choose the quote for my $i ( 0 .. $#Comment ) { if ($value eq $Comm[$i]) { $Como = $Comment[$i]; $Number = $i + 1; last; } }

    Your biggest problem was this line:

    my ('$i','$Como','$Number');

    Don't declare variables by putting them in single quotes. This may not fix your problem, but at least the program should run.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Stupid Program!
by dws (Chancellor) on Nov 30, 2001 at 03:02 UTC
    I had this darn app. working just last week. Now I can't get it to work on my web site.

    You've given us very little to go on (though source does help). What are you expecting to happen? What are you observing happens instead? What have you tried to diagnose the problem?

    Perhaps perusing the thread How to get the most of your question from the monks might help you post questions that are more liable to get you the help you need.

Re: Stupid Program!
by dragonchild (Archbishop) on Nov 30, 2001 at 02:22 UTC
    It might help to know what's wrong. Also, using warningsToBrowser(1) might help. :-)

    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: Stupid Program!
by CharlesClarkson (Curate) on Dec 01, 2001 at 04:47 UTC

    There's rarely a good reason for mixing routines with actual HTML. You are also using poorly formed HTML. By making a few assumptions, I was able to get this. It's easier to read and maintain without the HTML. It's also easier to write it this way.

    #!/usr/bin/perl use strict; use diagnostics; use CGI; # create a new CGI object my $page = new CGI; # used during testing # $page->param('Comic', 'Images/Le_Comic6.jpg'); # Grab a named CGI parameter my $comic = $page->param('Comic'); exit unless $comic; my $menu = $page->div({-class => 'Standard' }, $page->p( $page->cente +r( $page->a({-href => '../index.htm' }, '[Home]' ), $ +page->hr, $page->a({-href => '../Gallery.shtml' }, '[Gallery]' ), $ +page->hr, $page->a({-href => '../Manga.shtml' }, '[Manga]' ), $ +page->hr, $page->a({-href => '../Video_Review.shtml'}, '[Video Reviews]'), $ +page->hr, $page->a({-href => '../Links.shtml' }, '[Links]' ), $ +page->hr, $page->a({-href => '../Web_Comic.shtml' }, '[Web Comic]' ), $ +page->hr ))); my ($comment, $number, $comic_links); { my @file_names = qw| Images/Le_Comic.jpg Images/Le_Comic2.jpg Images/Le_Comi +c3.jpg Images/Le_Comic4.jpg Images/Le_Comic5.jpg Images/Le_Comi +c6.jpg Images/Le_Comic7.jpg Images/Le_Comic8.jpg Images/Le_Comi +c9.jpg Images/Le_Comic10.jpg Images/Le_Comic11.jpg Images/Le_Comi +c12.jpg Images/Thanksgiving_Comic.jpg |; # Open up the comments file open my $fh, '../Comment.txt' or die $!; my ($i, @links); foreach my $file_name ( @file_names ) { chomp( my $line = <$fh> ); ($comment, $number) = ($line, $i) if $file_name eq $comic; push @links, $page->a({-href=>"Testy.cgi?Comic=$file_name" +}, 'Comic #', ++$ +i); } $links[11] = $page->a({-href=>"Testy.cgi?Comic=$file_names[12] +"}, 'Thanksgiving Comi +c' ); $comic_links = $page->p( $page->b( $page->u('Comics') ) ) . $page->p( (join ' | ', @links[0 .. 4]), $page->br, (join ' | ', @links[5 .. 9]), $page->br, $links[10] ) . $page->p( $page->center( $page->u( $page->font( { -face => 'Comic Sans MS', -size => 4}) +)), $page->br, $links[11] ); } print $page->header, $page->start_html( -head => $page->Link({ -rel => 'stylesheet', -href => '../Style.css', -type => 'text/css'} ), -title => "Animetion Station > Webcomic > Comic #$number", -meta => { GENERATOR => 'Adobe PageMill 3.0 Win' } ); print # Web Comics $page->p( $page->center( $page->div( { -style => q| background-color: #0099FF; font-family: Comic Sans MS; font-size: 20px; width: 200px; color: white;| }, 'Web Comics' ))); print # Table $page->table( { -width => 757, -border => 0, -cellspacing => 1, -cellpadding => 0, -height => 294 }, $page->Tr( $page->td( { -width => '14%', -valign => 'TOP', -align => 'CENTER', -height => 293 }, $menu ), $page->td( { -width => '86%', -valign => 'TOP', -bgcolor => '#3366ff' }, $page->p( $page->center( $page->img( {-src => '../$value'} ) ) ), $page->br, $page->p($comment), $page->center( $page->div({ -style => q| font-family: Times New Roman, Time +s; color: white; width: 350px; background-color: gray; text-align: center;| }, $comic_lin +ks ) ) ) ) ), $page->end_html; __END__

    Charles K. Clarkson

    And he puzzled three hours, till his puzzler was sore.
    Then the Grinch thought of something he hadn't before!
    - Dr. Seuss

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://128474]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2020-09-25 20:05 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (140 votes). Check out past polls.