The Starman's Perl Pages

These pages will help you begin your study of
the perl programming language.
 

Perl icon
Get your perl icons
for Win 95/NT here!

Note: The perl software is actually FREE for anyone to use!
( See the links below for download sites! And installation instructions.)


I made this page primarily to help PC users interested in learning Perl, but
CGI-scripts for websites on "UNIX-type" servers will also be discussed here.


perl is sort of a cross between an interpreter and  a compiler:
It first examines the whole text of a perl program (.pl script) for any errors. But instead of running the commands from the interpreter, the script is then compiled  and placed into memory before being executed. Unlike other compilers though, this machine code is (usually) never saved as an executable file.


Although Perl is often associated with UNIX servers, its source code has been successfully "ported to" (compiled to run on) many other operating systems including
Windows95/98/NT and other PC systems. So, more programmers (both professional and amatuer) should be taking advantage of this rich and fascinating language which has had worldwide use for many years!

The perl INSTALL instructions are in a brightly
colored
TABLE further down the page!  

Two FREE digital books on perl ... download now:
(Note: They are both "offsite")

Teach Yourself Perl 5 in 21 days.zip [542 Kb]
and
Perl - Quick Reference.zip [119 Kb]
(Note: The server these files come from has them saved with coded spaces, so you'll see, e.g., Perl%20-%20Quick%20Reference.zip when you save them. Just rename the files anyway you like.)


And Here's a FULL online Tutorial
to help you learn perl:

Introduction to Perl & CGI Programming - A complete course of study at free-ed.net.
The course is presently built around the online version of David Medinets' book, Perl 5 By Example. Students who have no previous programming or scripting experience can expect to spend between 1 and 2 hours on each lesson, including the time for doing the hands-on examples and exercises. Typical completion time for the course is about 1 quarter, or 12 weeks. This course is very nice, and by saving all of the online pages you'll have a good reference book too!



How to associate .pl files with perl.exe
This allows you to simply double-click on the file name of your script while in Explorer and have perl execute the program.

  If you need to see some output lines from your perl program and Windows is closing the DOS-window BEFORE you can read it, then simply add these two lines just before the "exit;" statements in your script:

  print "Press the ENTER key to exit program ...";
  $pause = <STDIN>;  #Like a PAUSE statement in DOS .bat files


The Starman's perl Program Examples

You can find other valuable resources at the
PERL.COM Reference site
and
More PERL Tutorial links here.



New: Is that old perl script y2k compatible?



How to Download and Install Perl

The perl software can be downloaded from various sites which are
located all over the world. Collectively, these sites are known as

CPAN (the Comprehensive Perl Archive Network).

The perl software is usually stored in the archives as C-language source code which must be compiled into an executable program for your operating system. But the average home PC user certainly can't be expected to own a compiler like Borland's BC++ 5 or Microsoft's VC++ 6, and obviously doesn't have the free but very large GNU C-compiler that most UNIX users have access to. If, you're a PC user without a C-compiler (or you are running Windows™ 95/98 ), you need to find an archive site that has a pre-compiled (executable) perl interpreter for your operating system.
Which one do you want? Actually, there are two types of Win32 perl executables to choose from!
If you're a Microsoft® server administrator, run a Windows™ NT server on your home PC, or perhaps know that your webpages run on some kind of Microsoft® Server, then you should definitely read this page about the ActiveState version of Perl. If you work only with UNIX servers, but you still want to run some quick tests of a perl program on a Win 95/NT PC at home, perhaps you'll opt for the "standard port" described below.
I've installed and run both types of Win32-perl executables on my own PC, and believe that the standard version (as I'm calling it) is the quickest route for those just beginning to learn the language. However, I must defer to the experts as to which version is the best for your particular situation.

Note: I ended up switching to the ActiveState version years ago now, and if you have Windows ME, 2000 or NT I'd say that you should immediately start with ActiveState's version! It includes many packages for handling functions that occur only on Windows Systems.

This is the most efficient way I know of to download and install the Windows™ 95 / NT perl executable:

1) Click here:
http://www.perl.com/CPAN/ports/win95/Standard/x86/
The PERL.COM site automatically re-directs you to the next available CPAN site near you. (Pretty cool huh?!)
(Go ahead and click it now; it opens in a new window.)


2) Download the correct file:
Once you have been re-directed to the FTP site, you should already be in the CPAN// or pub/CPAN// or something...
ports/win95/Standard/x86/ directory.   Now look for the file:
perl5.00402-bindist04-bc.tar.gz   11-Aug-1997 00:00     4.9M (5,134,365 bytes)
IF you don't have the latest copy of WinZip which can read both .tar and .gz files, you may need to download the larger .ZIP file by the same name:
perl5.00402-bindist04-bc.zip       12-Nov-1997 00:00     5.9M (6,176,370 bytes)


This is the Win32 compiled version of the perl distribution. Please don't let the size put you off! There are many support files and loads of documentation that you may never use. I believe they're all required to be in any perl distribution. The parts you actually need to RUN perl on a PC are about 1Mb, but everything else brings the install size up to about 22Mb.


3) Extract the files to your ROOT DIRECTORY:

If you are using the new WinZip on the *.tar.gz file, you will see a dialog box like this before WinZip opens the package:
tar.gz in WinZip
Make sure you extract all of the files from the archive (*.tar or *.zip) into their proper folders! (Allowing the "directory tree" in the archive to be created on your drive.)
WinZip has a check box labeled "Use folder names" in its "Extract" dialog box that must be checked.
NOTE: Do not change anything after the files are created! This is only the initial step of the installation process.
The final name of your perl folder will be changed when you run the install program.
( The extraction itself takes almost 5 min. on a 100MHz PC since there are over 2200 files here. Again, don't let the amount of "support files" concern you. Perl itself is actually quite easy to begin using with any of the online tutorials or introductions to the language; see the links above for a free tutorial or book.)

4) Begin the Install:
Please review this summary before starting the process:
Perl Install Instructions.

In C:\ (or whatever your ROOT directory is), find the newly created perl5.00402-bindist04-bc folder and execute the install.bat file while at a DOS prompt. ( You may wish to review/learn how to use the features of a DOS-window in Windows™ at this time.)

Except for ONE question (about a compiler), the rest of the install process can be summarized in one phrase: `Keep pressing the ENTER key!'

The first question the install file asks is:
Where would you like Perl to be installed? [c:\perl]
Just press the ENTER key for the default, then you'll see:
Ok to create `c:\perl'? [y]
Press the ENTER key again. It then asks:
Do you have a C compiler? [y]
Unless you're already a professional programmer, you'll probably need to answer no (press the 'n' key) to this one. If you have the BC++ 5.02 compiler (especially if you are installing perl on a Windows™NT machine) it wouldn't hurt to add its location to perl's configuration; this does not affect the install process.

Other questions and comments include:
Install HTML documentation? (needs 4.5MB) [y]
Where should HTML be installed? [c:\perl\html]
Just keep pressing the ENTER key to each of these questions...
The install then shoots out a paragraph that may be difficult to understand, but even if you do not have a web server installed on your PC, it's probably best to accept the default in the next line:
Root of the perl HTML tree? [/c|/perl/html]
I had problems with the hyperlinks in the HTML conversion when I used the string `c:\perl\html.' So, just press the ENTER key again! (Accepting the `/c|/perl/html' default.)

The install program then summarizes what it's about to do:
We're now ready to copy files.
Perl will be installed in `c:\perl'.
HTML documentation will be installed in `c:\perl\html'.
Document URLs will begin at `/c|/perl/html'.
Proceed? [y]
Press the ENTER key, and take a short break ...
(On my 100 MHz Pentium machine, it took just 1 minute to copy the 1,207 program and module files and only 4 more minutes to do all of the POD to HTML conversions.) Click here for a listing of the perl install program's output lines (Opens in a new window).
On the last screen, the install program states (in part):
" You can do this in the `Environment' tab of the `System' Control Panel..." This is true ONLY in Windows™ NT -- there is NO "Environment Tab" in Windows™95!

You must add the location of PERL.EXE to your `PATH ':
If you asked for things to be installed under `c:\perl', then add " c:\perl\bin " to the " PATH= " statement in your AUTOEXEC.BAT file. (This change to your AUTOEXEC.BAT file will require you to reboot before it takes effect under Windows™95.)



5) Checking and Testing your new perl installation ("Standard" or "ActiveState" versions):

Quick Check:
After you've rebooted your computer, open an MS-DOS Prompt (or COMMAND.COM) window. You'll probably be in the Windows folder (C:\WINDOWS>) which is just fine for this test. Type in:  perl -v   (and press the ENTER key). Here's what you should see:
This is perl, version 5.004_02
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5.0 source kit.

(Or, for those with the ActiveState version, you'll see something similar to this):
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 629 provided by ActiveState Tool Corp.
http://www.ActiveState.com   Built 12:27:04 Aug 20 2001
(plus the license notes, etc.)

If you see the words, Bad command or file name, instead, then type:   path   (press ENTER) and make sure that
C:\PERL\BIN is somewhere in your PATH= statement. After correcting any errors in your AUTOEXEC.BAT file, you'll have to reboot again under Win95! (For WinNT users: change this in your SYSTEM Control Panel under the "Environment" TAB.)

Test 1.
At the DOS prompt, type in:   perldoc   ( press the ENTER key). You should see something like this:
Usage: PERLDOC.bat [-h] [-v] [-t] [-u] [-m] [-l]
PageName|ModuleName|ProgramName
PERLDOC.bat -f PerlFunc
We suggest you use "perldoc perldoc" to get aquainted with the system.
(The ActiveState version adds the switches [-F] [-X] and
perldoc.bat -q FAQKeywords to the functionality of perldoc.bat.)

Although perldoc is a DOS batch file in the C:\perl\bin folder, most of it is written in Perl. Yes, Perl script can be embedded within DOS batch files by placing it where DOS never sees it and making a "call" to the perl executable with a number of command-line switches.
[ Entering perl -x -S perldoc should produce the same exact output you saw above. DOS batch files like this one make things a lot easier for you.] (Unfortunately, perldoc.bat does not always operate as intended under Windows™95/NT as far as displaying the information on your screen one page at a time! This is especially true when using the - f switch! Here's my solution to this problem for a Windows™95 install: Batch file and perl script for proper paging of perldoc.bat output.)

Test 2.
At the DOS prompt, enter:  perldoc perldoc
The following is just the beginning of the documentation you'll see:
NAME
perldoc - Look up Perl documentation in pod format.
SYNOPSIS
perldoc [-h] [-v] [-t] [-u] [-m] [-l]
PageName|ModuleName|ProgramName

perldoc   -f   BuiltinFunction
Remember that you must use the -f switch in order to extract information about a function from the perlfunc documentation page.

Test 3: Let's run a little perl script !
Open NOTEPAD (or some other text editor) and copy the following lines into it:

#!perl
# A VERY simple Perl script
print " \n\n Hello from The Programming Republic of Perl ! \n ";
exit;


Now save (or rename) the file as:   test3.pl
If you're running Windows™95, it's best to save it as:
c:\windows\test3.pl
(since your MS-DOS prompt opens at C:\WINDOWS>).

Although the first line, #!perl , is NOT necessary to run a perl script under Windows™ 95/98/NT, it is good programming practice to make your perl scripts as portable (able to run on many different systems) as possible. On many UNIX-type systems, this line is written as: #!/usr/local/bin/perl and referred to as the "she-bang" line; possibly helpful in remembering that the "bang" character (!) follows the # character. This is a special line (not a comment) that tells those systems which understand it where they can find the perl executable. Windows™95/NT use the PATH statement and their Registry files (containing " file associations" ) instead. The perl executable will try to run any file you ask it to as a perl script, but it's also a good practice to use the .pl extension.

Let's execute the script:
Open a DOS (Command prompt) window, and enter the following at the prompt:   perl   test3.pl

Your screen should look similar to this after it runs:
test3.pl

If, instead, you saw something like this:
test3.pl.error
Then make sure that the file was NOT saved as test3.pl.txt (your text editor may have been set to save files as "Text Documents" only instead of "All Files" ). Also check that test3.pl is actually located in the folder you believed you saved it to (you may need to cd to the correct folder).

If there was some other kind of error, try running the script with the -w switch. This switch turns on &quoot;warnings" which can be VERY helpful when you start writing Perl scripts of your own! ( Under the "BUGS" section of perldoc perl, you'll find the humorous comment: "The -w switch is not mandatory" as a reminder of just how important this can be at times! ) Delete the file test3.pl when you're through using it.

Test 4: Testing some perl file-functions!
Most browsers can either save a file as anything you wish (Netscape), or at least as a text file (MS-IE). The following link opens a Perl script (saved as a text file) in a new window. Try saving the file directly as test4.pl in your c:\windows folder as we did above (or whichever folder is the easiest for you to access from a DOS prompt). If you must save it as a text file, then rename it to test4.pl:
Standard I/O and file functions test script. (First take a few minutes to read the comment lines inside of my perl script and try to picture what the program will do.)
OK, pop up your DOS window again, and execute the script by entering: perl test4.pl
This script will quickly test the ability of your perl installation to create a new file, write to it, append to it, read from it and finally delete it. In the process, it also tests the standard I/O (sending data to your screen and reading data in from the keyboard).

If you run the script with the -w switch, you'll see the warning:
Name "main::TTEST" used only once: possible typo at test4.pl line 58.
This is because I fully expect the file open function (which uses the "file handle" TTEST) to fail here. If it didn't, that would mean that there was an error in deleting ("unlinking") the temporary file!


You might like to check out my: Free Windows 95/98/NT Tools page here.

Please USE Your Browser's BACK BUTTON . . . . . or

Visit "The Starman's Realm" Home Page