Websailve.com logo


Why WebsAlive?

Web Hosting

Site Design

Customer Area

Getting Started

General Terms

Contact us

Software Web Design Dreamweaver First steps
html Domain Names Email Search engines
Security Apache PHP Javascript Perl/CGI Mysql

Perl and CGI

PERL is another of those open sourced things, this time its a scripting language, a bit like Javascript. Perl is extremely powerful and has been used on Unix platforms for years. Web programmers can make use of Perl by writing Perl scripts for the server and calling them from within the downloaded web pages, almost the same as PHP. Perl scripts for the web are usually saved as text files with a .cgi extension and usually in a special 'cgi-bin' directory, specially for executable files. As PHP is easier to use and more user-friendly, its probably not worth learning Perl. Contact me for some good reference material if you want.


By giving the server, files that are executable, some clever bleeders can tap into your server and cause havoc. There are safeguards for this but be aware. PHP is safer for server side scripts.


Perl is straight forward to install, and should run with Apache fairly quickly.

1. Download the latest from www.perl.org. Install it to c:\perl. Go with all of the defaults.

2. Copy the hello.cgi script below and save it as hello.cgi, preferably where you keep your web files. Open Windows (not internet) Explorer and double click on the hello.cgi you've just saved; a pop-up should ask you what to run the file with. Select Perl from the drop down and always associate with this application.

3. If Perl is working, double clicking on hello.cgi will open a dos command window, execute the script then close the window.. good, its working but not very useful. To see what is happening you need to open a dos command window, through the start menu>programs>MS Dos prompt.

4. At the prompt 'type perl -h' (without the quotes). A scree of help commands should come up. If 'bad file name' comes up then you must add the Perl directory to your path in your autoexec.bat file. If you installed Perl to c:/perl then at the prompt type 'c:/perl/perl -h', this should work, if not there is something wrong with the Perl installation.

5. By using cd to change directories to where you saved the hello.cgi, type 'perl hello.cgi' and html of hello world should scree past (or 'c:/perl hello.cgi' if the path isn't set). The dos command window is a useful, though awkward place, to debug scripts.

6. If you are running the server on your machine then the following should work: In your internet browser click on hello.cgi. You should see;
hello world!
in large, bold font with no tags or anything else. If this happens, then its working. If not then it will only work if the file is within your web directory. If no -worky, its the Apache conf file that needs tweeking - check the documentation.


# hello.pl -- my first perl script!
print "Content-type: text/html\n\n";
print <<EOF;
<TITLE>Hello, world!</TITLE>
<H1>Hello, world!</H1>

back start of guide next

Contact information for Websalive
Postal address: Scotland, UK: 113 Comiston Road,
Edinburgh, EH10 6AQ
Electronic mail: Support, Sales, General Information:
Last modified: August 14, 2006