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-
#!/usr/bin/perl
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"
> Yesterday i tried a "Hello world" program in perl using cgi script
> on a windows platform.
Check out the CGI module on CPAN.
> 3. opened it with my web browser.
>
> but now instead of giving the output it just shows the original
> source code. please help! regards
You have to configure your web server to execute CGI scripts.
Regards,
Alan Haggai Alavi.
--
The difference makes the difference
That won't do, you need to configure a webserver to execute that code. There are 2 ways to go about it:
1: install Apache, you can find a ready-to-go distribution at http://apachefriends.org
2: configure IIS to execute perl CGI, which is not extremely difficult, but requires you to know how to create a website on IIS.
Also, the top results on that search sadly still refer to ActiveState, so are not relevant anymore.
In a sense, what you need to do is add a .pl/.cgi association to IIS and configure it to open these files with Strawberry/perl/bin/perl.exe
If no further information will be given here by the time I get home (to a windows machine), I'll post a more thorough guide.
--
Erez
La perfection soit atteinte non quand il n'ya plus rien à ajouter,
mais quand il n'ya plus rien à retrancher.
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
regards
> Thanx alan..
You are welcome.
> please suggest the steps to configure my web server.
It depends on which web server you are using. You will probably find a
cgi-bin directory (in Debian/Ubuntu, Apache's cgi-bin is at
/usr/lib/cgi-bin/) which is configured to serve CGI scripts. Else, you
will have to configure the web server to allow another directory to
serve CGI scripts and copy the script there.
Otherwise, you can download Apache webserver, which comes with perl,
but the instructions for setting that up is different depending on your OS.
(http://httpd.apache.org/, http://perl.apache.org/)
> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
> http://learn.perl.org/
>
>
>
--
Abizer Lokhandwala