Why You Should Learn Perl and How to Install Modules Without Headaches


I’ve become a fan of the computer programming language Perl after my friend who majored in computer science recommended learning Perl over Python a month ago. For the longest time, however, I was getting pissed off trying to use it on my Mac.


Perl is a high-level computer language nicknamed the “Swiss Army chainsaw of programming languages” for its flexibility and adaptability. It can collect Edgar Allen Poe short stories from the Internet, calculate the similarities between them, and store that information in a database. Perl is free and is supported by tons of how-to books and online tutorials (e.g. here, here, and here). You don’t have to be a computer geek to learn Perl. You’d probably think of new applications for Perl by approaching it from a non-technical standpoint.

Now that I’ve convinced you to learn Perl, how do you get started?

Installing and Using Perl


If your computer’s operating system is Linux, you’re most likely a computer geek and don’t need to read this post at all.


If you have a Mac like me, you’re in luck. Macs (at least the ones in this generation) come pre-installed with Perl. To start using it save the code below in a plain text file (i.e. “.txt” extension) titled, for example, helloworld.txt.

print 'Hello world.';

Open the Terminal application and enter

perl path/to/helloworld.txt

You should see “Hello World” appear in Terminal (which I’ll also refer to from now on as the “command line” or “shell.” For the technical lowdown, click on the links). It’s that easy. Once you become familiar with Perl and want to do other cool tricks, you’ll want to install additional components called “modules.” You can find these modules on CPAN (Comprehensive Perl Archive Network). For example, the LWP module lets Perl interact with web pages, and the Mail::Sendmail module allows you to send e-mails. The easiest way to install modules is to type

cpan module::name

into the command line. Unfortunately, if you have Mac OS Leopard (version 10.5. You can check by clicking the apple icon on the top-left corner of your screen and selecting “About This Mac”), this might not work. You might get this error:

Writing Makefile for [module::name]

Way to be specific CPAN. I found out to my chagrin that the shell couldn’t find the crucial command “make” that’s needed to build extra modules. Entering “make” into Terminal returned

bash: make command not found

Suggestions on online forums told me to register an account and download Xcode, a Mac software development tool, that would supposedly provide me with the “make” command. No dice. It turns out the current downloadable version of Xcode on Apple’s website is compatible only with OS X Snow Leopard (version 10.6). Even if you manage to install the Leopard version of Xcode, you still have to put the “make” command in your PATH. After I did all this, I discovered some “header” file was missing from my CPAN configuration files. At this point, I simply gave up (especially after reading about how Apple may have seriously messed Perl up by updating software in OS X Leopard). I pinned my hopes on the chance that updating my MacBook Pro from Leopard to Snow Leopard might fix Perl. It did. Hallelujah.

Long story short: if you have OS X Leopard and want to install Perl modules, just upgrade to OS X Snow Leopard.

Microsoft Windows

You’ll need to download free Strawberry Perl or buy ActivePerl. I used Strawberry and gotten along fine with it long before I fixed Perl on my Mac.