Getting error

I'm trying to have a cgi script use a string from the window location in a template file. When I run the script I get Internal Server Error and when I go to my control panel error log it says Premature end of script headers. I was wondering if some experienced programmer would take a look at it and see what is wrong with it:

#!/usr/bin/perl -w

use CGI qw(:all);
use strict;

my $info;

if($info = param("info")){

print<<EOF;
<html>
<head>
<title>Template</title>
</head>
<body>
<!--#include virtual="index.cgi?i=epl&w=$info" -->
</body>
</html>

EOF

}else{

# Default stuff
<html>
<head>
<title>Template</title>
</head>
<body>
No result
</body>
</html>
}

Thank you, marringi

That's usually an indication that you have a syntax error in the script.

And sure enough:

vnix$ perl -c /tmp/cgi
Bareword found where operator expected at /tmp/cgi line 27, near "<title>Template"
	(Missing operator before Template?)
Bareword found where operator expected at /tmp/cgi line 28, near "</head"
  (Might be a runaway multi-line // string starting on line 27)
	(Missing operator before head?)
Semicolon seems to be missing at /tmp/cgi line 29.
syntax error at /tmp/cgi line 26, near "head>"
Search pattern not terminated at /tmp/cgi line 32.

There's a wrapper module for CGI which displays these types of errors on the generated page instead of that dreaded 500 Internal Server Error. You should probably use that at least while developing. (Search for "errors to browser"; can't remember what the thing is called ... ah, here: use CGI::Carp qw/fatalsToBrowser/;.)

Hi and thanks for the response

The thing is that I don't really know anything about perl programming. I'v tried to change some things in response to this, but with no luck. Do you have any idea what it is that needs to be done?

thank you

You're lacking a "print <<EOF" (and the corresponding EOF) inside the else part. Perl is seeing your bare HTML code and expecting it to be in Perl syntax, which obviously it's not.

Of course, it would make sense to factor out the duplication and concentrate on getting the variable part into a variable.

#!/usr/bin/perl -w

use CGI qw(:all);
use strict;

my $info;
my $response;

if($info = param("info")){
  $response = '<!--#include virtual="index.cgi?i=epl&w=$info" -->';
} else {
  $response = 'No result';
}

print<<EOF;
<html>
<head>
<title>Template</title>
</head>
<body>
$result
</body>
</html>
EOF

I hope I didn't overlook some difference between the two parts. (One of the reasons you should avoid duplication!)

Thanks for the quick response.

I tried this but I got this error:

Software error:

Can't find string terminator "EOF" anywhere before EOF at team.cgi line 15.

Any idea what this means?

You made a typo? Or forgot to read the whole reply?

print <<EOF;
Random text goes here
EOF

You're missing that last line there and it's telling you precisely that.

This is what I got, copied exectly what you wrote, didn't change anything?

#!/usr/bin/perl -w

use CGI qw(:all);
use strict;

my $info;
my $response;

if($info = param("info")){
$response = '<!--#include virtual="index.cgi?i=epl&w=$info" -->';
} else {
$response = 'No result';
}

print<<EOF;
<html>
<head>
<title>Template</title>
</head>
<body>
$result
</body>
</html>
EOF

Make sure you have a newline after the EOF.

You will need to change $result to $response, sorry about that.

I change $result to $response and made an extra line.

#!/usr/bin/perl -s

use CGI::Carp qw/fatalsToBrowser/;
use strict;

my $info;
my $response;

if($info = param("info")){
$response = '$info';
} else {
$response = 'No result';
}

print<<EOF;

<html>
<head>
<title>Template</title>
</head>
<body>
$response
</body>
</html>

EOF

Still getting the same error:
Can't find string terminator "EOF" anywhere before EOF at team.cgi line 15.

Empty line after the EOF was the idea. I got the exact same error here when I copy-pasted the code ...

Did that, now a new error:
Undefined subroutine &main:: param called at team.cgi line 9.

Have you gotten it to work?

Could you copy-paste what you got?

vnix$ chmod +x /tmp/cgi
vnix$ /tmp/cgi
<html>
<head>
<title>Template</title>
</head>
<body>
No result
</body>
</html>
vnix$ 

You wouldn't happen to have DOS carriage returns there or something?

I don't know. I'm justing buying hosting service from a company. Don't reaaly know much about their system.

The code you wrote, do I put it between print<<EOF; and EOF?

If you edited the file on a Windows computer and uploaded it in "binary" mode, that would put the wrong line-ending terminators there. But I just tested, and it doesn't seem to matter, as long as the line endings are consistent throughout the file.

Just to be on the safe side, can you make a copy of the script, and see if that works:

tr -d '\015' <oldscript >newscript
perl -c newscript

If yes then just move the newscript file on top of the oldscript file.

Nope, the whole script file begins with the shebang line #!/usr/bin/perl and ends with the EOF

Also, did you edit the correct file ...? (^:

Try replace it with just a "hello world" CGI and see that you get the expected output.

#!/usr/bin/perl

use strict;
use warnings;

use CGI::Carp qw/fatalsToBrowser/;

print "<html>\n";
print "<head><title>Tja</title></head>\n";
print "<body>Tj�nare, v�rlden</body>\n";
print "</html>\n";

I can't quite understand you. When I upload other cgi scripts, it is no problem, so I don't think it is that I am sending them in Binary form.

I don't really understand what you are saying that I should do. Has the script worked on your server?

ok, i'll try that

Also just to make sure there is no insidious cache anywhere which is holding on to the old version still, try to give it a completely new name. Some hosts use various mechanisms for loading a script into the server once, and keep it there, and you need to jump through some hoops to replace a faulty script.

Again I am getting Internal Server Error. I'm using Ipswitch WS_FTP Professional and it automatically sends all .cgi files in ASCII mode. I'm running another cgi script in the same directory so this is quit the mistory...