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

Hi all,

I am getting a "premature end of script headers" error. I am using POST and linking to another executable. It is a .cgi file and hence has the necessary following lines,

#!/usr/local/perl -w use strict; use CGI; print header;

On reading the suggestions from this forum,

I am accessing a DB using this code...

Code tags and formatting added by GrandFather

Replies are listed 'Best First'.
Re: Premature end of script headers.
by davido (Cardinal) on Jul 26, 2006 at 17:58 UTC

    Change the following line:

    use CGI;

    ...to...

    use CGI qw/:standard/;

    The problem is that the header isn't getting printed. It's not getting printed because you didn't ask it to be imported. The qw/:standard/; does that for you.

    If you check the error logs you would also see (in the error logs) why the script failed. Strictures will complain:

    Unquoted string "header" may clash with future reserved word at mytest +.pl line 8. Name "main::header" used only once: possible typo at mytest.pl line 8. print() on unopened filehandle header at mytest.pl line 8.

    Dave

Re: Premature end of script headers.
by ikegami (Patriarch) on Jul 26, 2006 at 17:59 UTC

    The first think you should do is get the error message from the error log file.

    The problem is that you never import header. Replace
    use CGI;
    with
    use CGI qw( :standard );

    Also,
    #!/usr/local/perl -w
    should probably be
    #!/usr/bin/perl -w

    I'm surprised by your claim that it works from the prompt. It shouldn't, and it doesn't on my machine.

    Unquoted string "header" may clash with future reserved word at 563851 +.pl line 4. Name "main::header" used only once: possible typo at 563851.pl line 4. print() on unopened filehandle header at 563851.pl line 4.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Premature end of script headers.
by Fletch (Bishop) on Jul 26, 2006 at 17:54 UTC

    When all else fails, check the server logs. If you don't know where they are, bug the support people or your sysadmin.

    (Having said that, one bets that /usr/local/perl should be /usr/local/bin/perl . . . )

Re: Premature end of script headers.
by Anonymous Monk on Jul 26, 2006 at 18:15 UTC
    Hello All, Thanks for replying, That was just the first few lines. I actual code is running perfectly +well. I did change it from use CGI; to use CGI qw( :standard ); (It was that way and I changed it to just CGI + upon reading a few solutions!) Also, my bad.. it is #!/usr/bin/perl in the program too.. just that I +kept sudo - ing through so many folders looking for the DB.. Any other suggestions are welcome.. Thanks.