Wednesday, August 6, 2008

Perl script Setup

There are four stages:

Get the software.
Install it.
Run a test Script.
Celebrate or troubleshoot.

1. Getting the Software
An old version of Perl for Win32 is included with the Windows NT Resource Kit. It is sadly out of date. Follow the steps below to get a newer version. Having said that, you can complete the tutorial with the Resource Kit version but you should upgrade as soon as you can.

Go to and follow the links to download ActivePerl. It will be a single file, and the name will be something like api508e.exe. The i stands for Intel. If you have an Alpha, download apaXXXe.exe. If you're not sure, download the Intel version.

The 508e is the version number, so expect this to change quite rapidly. The file size will be just over 5Mb, so it will take a while to download via modem. If you know how to use FTP, try

When you find ActivePerl, save the file into any directory you please. I like to organise my downloads into c:\downloads but that is just personal preference. As long as ActivePerl ends up on your hard disk somewhere it doesn't matter.

2. Installation
So you now have apixxxx.exe. If you forget where you saved it, don't panic, just run Windows Explorer and search for api*e.exe

Double-click the apixxxx.exe. You'll see the fantastic ActivePerl graphic and be advised to close all open applications before proceeding. The lizard thing is a gecko, which adorns the famous O'Reilly book "Learning Perl on Win32 Systems". This tutorial is aimed at a more basic level than that book, in terms of the author's knowledge, intended audience and quality of humour.
Agree to the license agreement or cancel the install, stop this tutorial and deny yourself any hope of hackership.
Destination directory is whatever you want. I usually install Perl in c:\progs\perl rather than c:\program files\perl because many Win32 programs don't properly handle long filenames, let alone those with spaces in. Or you could accept the default. Your choice.
Select Components. All you'll need for this tutorial is "Perl for Win32 Core", but installing the "Online Help and Documentation" and "Example Files" is highly recommended. If you run Internet Information Server (IIS) 3 or later, or Personal Web Server (PWS), then install "Perl for ISAPI" and "PerlScript" too, although don't try either of these until you are proficient with the basics. The phrase running before walking comes to mind.
Select Options.
"Associate '.pl' with Perl.exe". If you select this option then you can just type in the name of a script at the command line, or double-click it and the script will run. If you don't, then in order to get a script to execute you'll need to type:
to execute Personally, I prefer double-clicking to allow me to edit the file so I do not select this option. Also, perl has a plethora of command line arguments which are difficult to pass to a script if you run it by association. For the purposes of this tutorial I'm assuming that you haven't associated .pl with perl.
"Add the Perl bin directory to your path". Do this, otherwise you'll have to specify the full path to perl.exe every time you use it. Not fun.
"Standard I/O redirection for IIS". If you run IIS or PWS, select this. It is a Good Thing. Understand it later.
IIS Options If you use IIS or PWS you'll have this screen -- just accept both options.
Program Folder whatever your preference is. This is just a link to the documentation, to the perl.exe itself.
Confirmation make sure that what is displayed is what you have selected...
The install program will now copy files. At the end it will run a few perl scripts itself, which briefly appear as DOS boxes. Don't worry, it is all quite normal.
Release notes. Well worth a read.
Reboot! Just so the path statement takes effect. In any case, it is always good practice to reboot after a new install.

3. Testing - Your First Perl Script

So you know what this tutorial is designed to do. You know what Perl is designed to do, and you have even installed it. It is now time to start the tutorial proper, and actually hack some code.

No comments: