Getting Started w Perl
Volume Number: 16
Issue Number: 9
Column Tag: Tools of the Trade
Getting Started with Perl
By Larry Taylor, Edited by Steve & Patricia Sheets
Open Source power scripting for Macs
Perl is a programming/scripting language developed under Unix, which is distributed
under the GNU license and now runs on most platforms, including MacOS. It is the
language of choice for Unix system administration, CGI scripts and other goodies. More
relevantly, it can really expand your ability to accomplish things on the Mac. In this
article I describe a frustrating problem I had and a step by step Perl solution. I hope
this example will encourage you to learn Perl and use it. Perl scripts are just text
files and so are fairly easily portable across platforms making Perl even more useful
if you need to solve the same problem on several platforms. Learning Perl is not
difficult and it looks great on your resume, so why not give it a try?
Mac + Perl = MacPerl
Perl arouse because many UNIX programmers wanted a quick alternative to C, with
many of C's features. The result was a full-featured, easy to use, C-like programming
language. Perl has been ported to the Mac where it can be used to create
pseudo-applications called droplets. I call them pseudo because they do not have
individual types and creators and so they must either be opened by double clicking or
by dragging a document onto them. They are interpreted and so need the Perl
interpreter in order to run. No Mac interface is needed to get information in or out, so
Perl is ideal for projects that involve reading some data, analyzing it, and outputting
some conclusions, projects for which the event-loop paradigm is more of an annoyance
then a help (although Cmd-period will stop runaway Perl droplets). One can construct
compiled applications with a full Mac interface, but the files are large and the
advantages over C largely evaporate. I use Perl for tasks as varied as extracting data
from files to emailing students in a class their exam scores.
Perl is "open source" software. The interpreter is available to download for free at
<http://www.iis.ee.ethz.ch/~neeri/macintosh/perl.html>, or the book "MacPerl,
Power and Ease" by Vicki Brown and Chris Nandor (#1-881957-32-2) from Prime
Time Freeware <http://www.ptf.com> contains a CD with the interpreter and lots of
other useful stuff. The book itself is a nice introduction to programming in general and
Perl in particular. Additional Perl stuff can be gleaned from the net. Try starting at
<http://www.perl.com>.
The Problem
Got one of those cool digital cameras that saves images to floppies? Then you know the
files are labeled automatically, MVC-01L.JPG, MVC-02L.JPG, etc. Copy the images to
your computer and you're in business. But suppose you went wild and filled up two
disks? Or ten? Files on different floppies often have the same name, so you can't just
copy them to the same folder. So you copy one floppy, change all the names of the files,
copy the second, etc. - bummer. Even with just a few images, you tend to put them in a
folder with a useful name since otherwise you won't remember what the pictures are
about, can't search for them with Sherlock, etc. Wouldn't it be nice to have them
named, whatever1.jpg, whatever2.jpg, etc.? This is a perfect job for a script.
The script should begin with a folder named whatever and look inside it for all the MVC
files and rename them as whatever1.jpg, whatever2.jpg, etc. It should even be a bit