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

premature end of script headers?

by Anonymous Monk
on Feb 22, 2007 at 17:35 UTC ( #601602=perlquestion: print w/replies, xml ) Need Help??

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

Can someone tell me why I get that error when using this code? I have to check my cpanel error logs because it just loads a 500 internal server error whenever I load the script.

#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; print header, start_html; use CGI::Carp 'fatalsToBrowser'; use LWP::Simple; my $page = ""; my $content = get($page); my ($guests) = $content =~ m/\d+\s+Guests/; my ($users) = $content =~ m/\d+\s+Users/; print "$guests and $users";

Replies are listed 'Best First'.
Re: premature end of script headers?
by Fletch (Chancellor) on Feb 22, 2007 at 17:46 UTC

    Consult the server's error logs and you'll see that you're getting a prototype mismatch error because two things are trying to declare the subroutine head with different prototypes.

    If you bother to read the documentation for LWP::Simple it explains just why you're getting that error and what the workaround is.

    Note that if you are using both LWP::Simple and the very popular CGI.pm module, you may be importing a head function from each module, producing a warning like "Prototype mismatch: sub main::head ($) vs none". Get around this problem by just not importing LWP::Simple's head function, like so:
    use LWP::Simple qw(!head); use CGI qw(:standard); # then only CGI.pm defines a head()
    Then if you do need LWP::Simple's head function, you can just call it as LWP::Simple::head($url).
      I agree that the change you suggested is recommended, but that shouldn't cause the problem he is experiencing as the warning is printed to STDERR and doesn't interfere with the header.

      I tested the script locally with apache 1.3.34 without any problems.

        Hrmm, quite correct that won't cause a 500.

        At any rate, the real next step should be to look at the error log and see what exactly the real error is that's causing the code to die and work from there.

        (And then fix things with use LWP::Simple qw( get ), of course :)

Re: premature end of script headers?
by ikegami (Patriarch) on Feb 22, 2007 at 18:08 UTC

    Just a quick note. Despite it's location, print header, start_html; is only executed after all the uses have been executed. If you want it to execute there, wrap the line with a BEGIN { ... } block.

Re: premature end of script headers?
by sulfericacid (Deacon) on Feb 22, 2007 at 17:42 UTC
    print header, start_html();


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-01-18 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (54 votes). Check out past polls.

    Notices?