1

I have the following CGI script:

#!c:\cygwin\bin\perl.exe

use CGI qw(:standard);

my $query = $CGI->new;

print header (
  -type   => "text/html",
  -status => "404 File not found"
);

print "<b>File not found</b>";

This gives me an error:

Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
End of script output before headers: test.cgi

If you think this is a server error, please contact the webmaster.
Error 500
127.0.0.1
Apache/2.4.10 (Win32) OpenSSL/1.0.1h PHP/5.4.31

I've looked at this (and other similar) question(s), but there the headers were not being printed, as opposed to mine.

I'm using the XAMPP Windows package with Cygwin Perl.

Can anyone help? Thanks.

Community
  • 1
  • 1
  • 5
    Internal server errors mean you should read the server logs, where you can see the error message perl is outputting before it dies. – Quentin Nov 30 '14 at 18:21
  • 6
    You *must always* `use strict` and `use warnings` at the top of *every* Perl program you write. This applies especially if you are asking others for help with your code, as it is a very simple first debugging step. In this case you would have seen the message `Global symbol "$CGI" requires explicit package name` which is precisely the cause of your problem. – Borodin Nov 30 '14 at 18:49

2 Answers2

4

I don't know why you are using $CGI instead of CGI

I think It should be

my $query = CGI->new;

tested on Linux working perfect.

Arunesh Singh
  • 3,489
  • 18
  • 26
2

So, as others have pointed out, your problem was using a variable ($CGI) where you actually needed a class name (CGI). But, in my mind, this raises two more questions.

1/ Why are you trying to create a CGI object in the first place? You are using the function-based interface to CGI (print header(...) for example) so there's no need for a CGI object.

2/ Why are you writing a CGI program in 2014? Perl web programming has moved on a long way this millennium and you seem to be stuck in the 1990s :-/

Dave Cross
  • 68,119
  • 3
  • 51
  • 97