On 11/04/2011 12:05, prashant kaushal wrote:
Hi Di,

Yesterday i tried a "Hello world" program in perl using cgi script on a windows 
platform. The steps i followed were:

1. Made a directory in "C:" and named it "cgi-bin"
2. Wrote  my source code file and saved it with "test.cgi"

#############################################################################
Source code-


print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello Word - First CGI Program</title>';
print '</head>';
print '<body>';
print '<h2>Hello Word! This is my first CGI program</h2>';
print '</body>';
print '</html>';

1;
##############################################################################

3. opened it with my web browser.

but now instead of giving the output it just shows the original source code.
please help!
regards

PS: software that I've installed on my pc is "Strawberry perl plus padre"

Fist of all, either change the line

   #!/usr/bin/perl

to reflect the true path to the perl compiler on your machine. Either
that or change the file type to .pl and make the association with the
compiler.

Secondly, you don't need to print "\r\n" as line terminators. This will
only do what you want if you 'binmode' the output stream; otherwise "\n"
will be output as CR LF, and adding a preceding "\r" will produce CR CR
LF, which doesn't comply with HTTP standards.

Now, you are opening a Perl program file in a web browser. The browser's
job is to interpret what it receives (whether from a local file or a
remote HTTP server) and present it on screen. It expects HTML data (or
perhaps XML) and does its best with any other content by presenting the
data just as it is. There is never any possibility that the browser
should know to /execute/ a Perl program if it sees one; indeed any CGI
code must be run on the server so that it has access to the server's
environment: files, databases etc.

So it is the server's job to run your Perl program and pass its output
to the browser for display. But you have no web server - all you have is
a file, so the browser displays the data from that file.

You must install and configure an HTTP server. The configuration will
determine whether the contents of a given file should be served
unmodified, or be run as a program and the output delivered instead. It
is quite possible to run a server process on the same machine as where
the file and web browser exist, but expect to do a lot of reading to
understand the details of the configuration.

On Windows you should install the 'World Wide Web Services' features.
Unfortunately this is not the forum to help you further with that.

I hope this helps you.

Rob




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to