Виртуальная песочница (тм)

Saturday, March 19, 2011

4 easy steps to start Perl CGI programming on Windows in 10 seconds or less

1. Download Active Perl and install it.
2. Download Apache for Windows and install it.


03/19/2011 01:11 PM 25,704,148 ActivePerl-5.12.3.1204-MSWin32-x86-294330.msi
03/19/2011 01:20 PM 5,400,576 httpd-2.2.17-win32-x86-no_ssl.msi
2 File(s) 31,104,724 bytes

(now start counting those 10 seconds)

3. Go to
C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin
and create test.cgi file with the following contents
#!C:\perl\bin\perl.exe -wT
use strict;
use CGI;
my $query = new CGI;
print $query->header( "text/html" );
print <<END_HERE;
<html>
<head>
<title>My First CGI Script</title>
</head>
<body bgcolor="#FFFFCC">
<h1>This is a pretty lame Web page</h1>
<p>Who is this Ovid guy, anyway?</p>
</body>
</html>
END_HERE

(make sure to hit "enter" a couple of times after END_HERE, otherwise it won't work)

4. Open
http://localhost/cgi-bin/test.cgi
in the browser. Enjoy.

Thanks to PerlMonks.org for the article.

P.S. PerlTutorial.org gives a bit more consequent example:
#!C:\perl\bin\perl.exe -wT
# It's always a good idea to use the strict pragma while developing
# Perl code, it makes Perl warn about dangerous code
use strict;

# We're also going to include the CGI module, so that we can take
# advantage of other programmer's efforts (One of Larry Wall's basic
# tennants is that programmers are fundamentally lazy -- he's probably
# right, but I can't be bothered to prove it right now)
use CGI;

# instantiate a new CGI object
my $cgi = new CGI;

# perform a single print statement, with liberal use of the perl
# string concatenator "." and some CGI methods
print
$cgi->header .
$cgi->start_html('Hello World!') .
$cgi->h1('Hello World!') .
$cgi->end_html;

# Tell the web server everything is fine
exit (0);

No comments: