Dave Cater

Perl - for portable scripts

 
Home Page
Career outline
Java
Linux
Security
Perl
Perl references
Perl - processing HTML
Perl - for portable scripts
System management
Testing
Musical notes
During an earlier project (Perl - processing HTML) I developed a Perl script html_mklinks.pl which processes HTML format input files. This was originally developed under Linux, and was used to process the HTML files which make up this site, to ensure the hyperlinks are kept up to date. I had to close down Windows and restart Linux just to run the Perl script. What I needed was a Windows version of Perl. I came across just what I was looking for on a CD supplied with the May 2000 edition of PC Plus magazine - ActivePerl. This was based on version 5 of Perl (just like my installed Linux version).

ActivePerl installed easily via a self-extracting executable containing an InstallShield-type package. Using the default options it installed into a perl directory on the C drive, including html documentation. This consisted of three separate products . So far, I have only looked at the first:

  • Perl for Win32 - Perl interpreter and libraries and utilities used by the other products
  • Perl for ISAPI - A plug-in designed to run Perl scripts faster on ISAPI compliant Web servers
  • Perl for ActiveX - An ActiveX scripting engine - this allows Perl-like code fragments to be embedded in other script languages, using a tag <SCRIPT LANGUAGE="PerlScript">..

The installation process updated the Windows system files to include the Perl utilities. After a reboot, I was able to start a DOS session and run Perl scripts as suggested in the PC Plus article, for example:

perl myprog.perl

In other words, I was close to being able to run html_mklinks.pl, the Perl script earlier developed under Linux. I wanted to be able to run the script with arguments and use pattern-matching as in the Linux shell (currently the default shell, bash). How was this to be achieved ? I hit on the idea of wrapping the HTML processing in another Perl script, html_files.pl, which uses Perl regular expressions for pattern matching, to select the files to be processed. This in turn gave me an idea for another project - to write a general purpose script to run commands with options and arguments within DOS.

Before digressing too far, its worth noting that the only changes needed to my Perl scripts to work under DOS were those connected with running external commands. Clearly, references to Linux commands such as `ls [0-9]*.html` were not going to work! This was easily fixed by changing the scripts to open and read directories entries, using "grep" to filter the resulting Perl arrays, and "sort" to order the results. In the course of this, I discovered the "-d" option which runs a Perl debugger - for anyone used to command line debugging, this should hold no fears.

So I had achieved my goal of implementing a Perl environment to run portable scripts.