Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Script not returning header

by ProgrammingAce (Sexton)
on Mar 09, 2002 at 03:40 UTC ( [id://150494]=perlquestion: print w/replies, xml ) Need Help??

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

Ok, this has been driving me nuts forever (actually a year and a half, but you get the point). I've been trying to get CGI to work on the free service tripod (yes, i know that's my main problem but read on...). To get to the end of the story, can anyone tell me why this script give me the error: "This page does not return a header"

#!/usr/local/bin/perl use CGI qw(:standard); use strict; print header; print "<p>Hello, World</p>";

And yes, I'm sure that it has the right path to perl. If I manually print the header, it gives me the same problem. Does anyone have any ideas?

        - Ace "Two programmers walk into a bar, the third ducks"

Edit ar0n -- title change

Replies are listed 'Best First'.
Re: Script not returning header
by BrentDax (Hermit) on Mar 09, 2002 at 08:29 UTC
    Are you sure it gets to the point where it would return the header? This might be a problem if, for example, they don't have If that's not the case, try unbuffering STDOUT with $|++.

    Sorry I'm not much help. This looks like a very weird problem.

    --Brent Dax
    There is no sig.

Re: Script not returning header
by fuzzyping (Chaplain) on Mar 09, 2002 at 05:03 UTC
    I may be way out of line here (I am not a CGI expert), but I don't think you're using any CGI objects. The point of including the CGI module is so you can use it. ;-)
    #!/usr/local/bin/perl use CGI; use strict; my $cgi = CGI->new; print $cgi->header, $cgi->start_html, $cgi->p, "Hello, World!", $cgi->p, $cgi->end_html;

    Once you've created the $cgi object, you can direct your methods (header, start_html, p, end_html, etc...) against it. In your example, you're not really printing anything... "header" doesn't exist (AFAIK).

    On a side note... and I expect to get thoroughly flamed (or at least lose some XP) for this, but I recently sat through a talk given by dominus. It was altogether enlightening in understanding some of the hidden "red flags" that plague beginner- to intermediate- (perhaps even some advanced) Perl programmers. I found his philosophies on the strict pragma particularly interesting. He made note of the (unpopular) fact that many Perl coders overuse 'use strict' without really even knowing why they're using it. Your snippet is a perfect example... you've used strict (out of forced behavior, no doubt) without any need. What have you declared? You don't have a single var, ref, or sub.

    I'm not saying that the strict pragma isn't a needed practice... just that perhaps we (I'm not excluding myself from this) should study the reasons for its practicality.


    Update: Removed "qw(:standard)" from the CGI call. As theguvnor noted, it's not necessary when using the dedicated OO format.
      Actually, by importing the :standard list of functions from the module and using its function-oriented style, you do not need to declare a CGI query object. Or, conversely, if you want to use's object-oriented methods as fuzzyping has demonstrated, then the qw(:standard) import statement is unnecessary. Either way works, it's a matter of taste (I prefer the OO style).

      Hope you don't take this as a flame :)


Re: Script not returning header
by screamingeagle (Curate) on Mar 09, 2002 at 04:02 UTC
    maybe you should specify the content-type first ?
    you are also using a semi-colon instead of a comma at the end of print header here's a sample code (stolen from the documentation :-) )
    print header, start_html('A Simple Example'), h1('A Simple Example'), start_form, "What's your name? ",textfield('name'),p, "What's the combination?", p, checkbox_group(-name=>'words', -values=>['eenie','meenie','minie','moe'], -defaults=>['eenie','minie']), p, "What's your favorite color? ", popup_menu(-name=>'color', -values=>['red','green','blue','chartreuse']),p, submit, end_form, hr; if (param()) { print "Your name is",em(param('name')),p, "The keywords are: ",em(join(", ",param('words'))),p, "Your favorite color is ",em(param('color')), hr; }
      "you are also using a semi-colon instead of a comma at the end of print header "

      so?? do you think that's the problem?

      using semi-colon means that it's the end of the statement, while a comma means a list, what you are actually doing, is using a list with a single print statement.. and this is not the problem here.

      print header, start_html('A Simple Example');
      basically does the same thing as :
      print header; print start_html('A Simple Example');

      He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

      Chady |
Re: Script not returning header
by ProgrammingAce (Sexton) on Mar 09, 2002 at 09:07 UTC
    I think i figured out the problem, I went back an used a CGI object, and it worked. I assume (and we all know what happens when you assume...) that tripod castrated the file so that now all you can use is the OO part... here's working code:
    use CGI; $q = new CGI; print $q->header, $q->start_html('hello world'), $q->h1('hello world'), $q->end_html;

    Thanks for all of your help

            - Ace "Two programmers walk into a bar, the third ducks"

      If you're using the version Tripod offer, it's a horrendously outdated copy of -- 2.30 (dated 1997 ... the horror!)


      I don't think that the is in itself castrated or changed in anway - I downloaded the file and it appears to be an unchanged 2.30 version, I think that it is something else that tripod is doing as I mention in Re: Script not returning header ...


Re: Script not returning header
by gellyfish (Monsignor) on Mar 09, 2002 at 12:09 UTC

    It's something weird about the environment that CGI programs are executed in on Tripod.

    I tested this on Tripod and I couldn't get it to work when using in the functional style - however it does work if you are using it in the OO style:

    #!/usr/local/bin/perl use strict; require CGI; my $cgi = CGI->new(); print $cgi->header(),"\n"; print "<p>Hello, World</p>";

    I don't know what is going on here though ...


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-12 15:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found