Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

by Angharad (Pilgrim)
on May 24, 2005 at 17:01 UTC ( [id://460085]=perlquestion: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: simple cgi script error
by davidrw (Prior) on May 24, 2005 at 17:16 UTC
    In general, it means something it spitting out output (on STDIN or STDOUT) before your print your headers. Simply try to run this script on the command line and you will see that it produces this error:
    Undefined subroutine &main::param called at /tmp/blah line 9.
    Check the CGI man page for details, but doing use CGI qw/:standard/; should resolve it.
Re: simple cgi script error
by gryphon (Abbot) on May 24, 2005 at 17:18 UTC

    Greetings Angharad,

    Debugging through PM posts isn't optimum for this sort of thing, but here are a couple of ideas that come my mind:

    • Ensure the file is a UNIX file, not DOS
    • Ensure the #! line is at line 1
    • Remove the first print line and replace with one of the two following things:
      • my $cgi = new CGI; print $cgi->header;
      • use CGI qw(header); print header;
    • Run the script from the command-line and post what you get

    gryphon
    Whitepages.com
    code('Perl') || die;

Re: simple cgi script error
by tcf03 (Deacon) on May 24, 2005 at 17:44 UTC
    Adding the following to my scripts when I was figuring this sort of thing out helped greatly.
    use CGI::Carp qw(fatalsToBrowser);
    To clean it up in general I would do it this way
    #!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $value=param('tapas'); print header; print start_html; print "Your favorite Tapas place in Barcelona was $value"; print end_html;
    I didn't test that, but it should work. But of course thats just one way. perldoc CGI is also a good source of information.

    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson
Re: simple cgi script error
by djohnston (Monk) on May 24, 2005 at 17:17 UTC
    I've never used CGI before, but I believe you need to import param.

    use CGI qw/param/;

Re: simple cgi script error
by sh1tn (Priest) on May 24, 2005 at 17:19 UTC
    Please, take a look at the apache error log, somewhere in /var/log/ probably.
    Is it chmod +x script?


Re: simple cgi script error
by holli (Abbot) on May 24, 2005 at 18:26 UTC
    I'm not sure if it makes a difference, but that should be
    print "Content-Type: text/html\n\n";
    (Note the uppercase "T" in "Type")


    holli, /regexed monk/
Re: simple cgi script error
by Angharad (Pilgrim) on May 25, 2005 at 09:54 UTC
    Hi again
    Thanks for the advice. I have tried everything that was suggested but the error still remains. When I run the script from the command line I get the following.
    Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"><head><title>Untitled Document</title> </head><body>Your favorite Tapas place in Barcelona was green</body></ +html>
    So, it seems to be working Ok per se. Maybe my server configuration still isnt quite right?
      I am wrote a small object oriented code snippet based on u r code.
      #!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $cgi=CGI->new(); print $cgi->header(); print $cgi->start_html(); my $value=$cgi->param('tapas'); ## No form check if possible print "Your favorite Tapas place in Barcelona was $value"; print $cgi->end_html();
      I haven't tested this, but should work

      Also, In your code code snippet, print the header first then try to call param().

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found