tags:

views:

37

answers:

3

I have a perl CGI script that needs to send back some HTML

print qq^Content-type: text/html\n\n
<HTML>
<HEAD>
<TITLE>some title</TITLE>
...
...
...
...
^:

Instead of seeing the rendered HTML in the browser, I see the entire HTML along with the tags and the 'content-type' line in plain text. Below is how things look in the browser -

Content-type: text/html


    <HTML>
    <HEAD>
    <TITLE>some title</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" BACKGROUND="" onLoad=document.forms[0].elements[0].focus();>
+1  A: 

Seems like HTTP-header is sent before the output. Do you have any print statements (possibly in some function) before this code?

Also, try enabing warnings and strictures (if you have them off).

eugene y
Yes. But that is not the case with me. I created a test 'hello world' CGI script that behaves the exact same way.Could some thing be wrong with the way perl is setup/configured on the server?
Wikidkaka
+1  A: 

Also, as CGI scripts can be called without a web server, just call the script manually (with the right parameters / environment variables if they matter to the script and look at the output. As indicated by eugene y, the request headers must be the first output from the CGI script for them to be picked up by the server.

Paul de Vrieze
A: 

It sounds as if your server hasn't been configured to recognize certain file types as cgi executables. Assuming you are using Apache, adding this line to your httpd.conf will do the trick, although there are many other ways of configuring this to achieve the same effect:

AddHandler cgi-script .cgi .pl

You may also have to add ExecCGI to an options list for your domain. See Apache Tutorial: Dynamic Content with CGI for more information.

Ether