Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

CGI Configuration Woes (was: newbie alert)

by deriwana (Initiate)
on Jun 18, 2001 at 23:22 UTC ( [id://89409]=perlquestion: print w/replies, xml ) Need Help??

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

Could someone tell me why I'm getting a "page not found"error on this script?I understand that it could be a number of reasons, but if something obvious pops out at you..please let me know.
#!usr/local/bin/perl use strict; use CGI; $query =new CGI; $guest_file = "../new_guestbook.html"; &print_page_start; if ($search_name = $query->param('search_name')) { eval { open (GUESTS, "< $guest_file") or die "Can't open $guest_file: $!"; while (<GUESTS>) { chomp; ($name, $email, $comments) = split /::/; if ($name =~ /$search_name/i { print "$name<BR>\n$email<BR>\n$comments<BR>\n<HR>\n"; } } } } else { print "<FORM>\n"; print "<INPUT TYPE=\"text\" NAME=\"search_name\"><BR>\n"; print "<INPUT TYPE=\"submit\">\n"; print "</FORM>\n"; } chomp $@; if ($@) { print "ERROR: $@<BR>\n"; } &print_page_end; sub print_page_start { print $query->header; print "<HTML>\n<HEAD>\n<TITLE>Search for Records</TITLE>\n"; print "</HEAD>\n<BODY>\n"; print "<H1>Search for Records</H1>\n; } sub print_page_end { print "</BODY>\n</HTML>\n"; }
update by neshura

Replies are listed 'Best First'.
Re: CGI Configuration Woes (was: newbie alert)
by Hero Zzyzzx (Curate) on Jun 19, 2001 at 00:21 UTC

    Well, here's a problem that's a likely culprit:

    You're using strict, GOOD! Keep it in there.

    However, your $query variable isn't declared as a global or with "my" (preferred).

    Change the line $query = new CGI; to my $query= new CGI; and you've fixed this variable so it can run correctly under strict.

    You should declare variables with "my" when you're using strict, which, of course, you're always doing : )

    Here's a great node on scoping.

Re: newbie alert
by buckaduck (Chaplain) on Jun 18, 2001 at 23:32 UTC
    Guess #1: The program is not world-executable. Use chmod to set the permissions to 755, for example.

    Guess #2: Your program dies (perhaps while opening the file?) but you can't see the error, because it's being written to your web server's error log. If you use the following module, runtime errors will also be shown to the browser:

    use CGI::Carp qw(fatalsToBrowser);

    Update: Belated Guess #3: The program may have a typo and not compile at all. What happens when you run it from the command line rather than through the browser?

    Update: I should point out that the question was originally asked in this node, where there are a number of replies that address some general coding improvements.

    buckaduck

Re: CGI Configuration Woes (was: newbie alert)
by scottstef (Curate) on Jun 19, 2001 at 17:49 UTC
    Try using a -w at your header and use diagnostics; with your program and see what you get. As a newbie the info that it points out has been invaluable for learning to write code. You can always takes these out when your program works correctly.

    "The social dynamics of the net are a direct consequence of the fact that nobody has yet developed a Remote Strangulation Protocol." -- Larry Wall

Re: newbie alert
by deriwana (Initiate) on Jun 18, 2001 at 23:24 UTC
    Sorry...that should be "PAGE CANNOT BE DISPLAYED" error..
      There are a couple of problems with your script:

      1) You are using use strict but you do not declare your variables with my

      2) On line 18 you are missing an ending parenthesis )

      3) On line 42 you are missing a end quote "

      HTH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found