Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Program can't work on website; please examine code

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

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

This node falls below the community's threshold of quality. You may see it by logging in.

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.

    Cheers,
    Ovid

    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 CGI.pm 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__



    HTH,
    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found