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

hi all, my script gives the " premature end of script headers " error in server log . i have checked every possible reason as such. the script is not dos formatted , no warnings or error other than end of script headers. dont know where to look . script runs fine on commandline and the location of perl interpreter is correct. here's the script see if you can make out something of it.
#!/user/bin/perl -w BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } use Fcntl; # find the keyword in gutenberg.txt #@gut_results; @gutenbergr = (1..56522); array_shuffle (\@gutenbergr); $filename = 'gutenberg.txt'; open (GUT, "< /home/sid/kwicionary/$filename") or die "Can't open $fil +ename for reading: $!"; $path = "/home/sid/kwicionary/"; $indexname = "$filename.index"; sysopen(IDX,$indexname, O_CREAT|O_RDWR) or die "Can't open $indexname +for read/write:$!"; build_index(*GUT, *IDX) if -z $indexname; $key = $FORM{'search'}; GUT:foreach (@gutenbergr){ print "$#gut_results \n"; $limit = 100; $line_number = $_; $line = line_with_index(*GUT,*IDX,$line_number); if ($key =~ /\*/){ # $key = substr($key,0,(length($key) -1)); @word = split(' ',$line); foreach (@word){ if ($_ =~ /$key/){ push (@gut_results , $_); if ($#gut_results == 100){last GUT;} } } } else { @word = split(' ',$line); foreach (@word){ if ($_ =~ /^$key$/){ push (@gut_results , $_); if ($#gut_results == 100){last GUT;} #print "matched gutenberg '$_' \n"; } } } undef @word; if ($#gut_results eq $limit){last GUT;} } undef @gutenbergr;
all i get in server error log is
Premature end of script headers: search.cgi (2)No such file or directory: exec of '/var/www/cgi-bin/authenticate/s +earch.cgi' failed
also, cannot understand which file the server could not find. I am including none. can somebody help??

Replies are listed 'Best First'.
Re: premature end of script headers
by Joost (Canon) on Oct 23, 2004 at 15:00 UTC
      thanks. that is why you guys are so great , coz you see what i could not .
Re: premature end of script headers
by davido (Cardinal) on Oct 23, 2004 at 15:04 UTC

    The webserver failed to execute /var/www/cgi-bin/authenticate/search.cgi probably because the path to perl is wrong in the shebang line at the top of the script. "No such file or directory: exec of..." is pretty much showing you that the script was found, but it failed to invoke a known interpreter or compiler.


    Dave

      i checked the path again and it is  /usr/bin/perl . also, another script runs fine with the same path .

        Yes, the path to perl is /usr/bin/perl. But as someone else said, look at the first line of your script, where you tell the OS where to find perl! Let me line it up on a chart below:

        Path to Perl.....: /usr/bin/perl Your Shebang Line: #!/user/bin/perl What's wrong: ^ | | Get rid of that 'e' in the first line of your script.

        Thus, the path to perl is wrong in your shebang line. What you have in the shebang line of your script does not match where perl is located on your system. If it works executing it from the command line, it's probably because you're typing perl scriptname, so the shebang line's path to perl is circumvented.

        Note I keep using 'perl' instead of Perl, because we're talking about the path to perl, the executable program, not Perl, the broader language.


        Dave