CPAN: Perl’s Best Friend (Part 1)

—Darian Lewis,

Before we can discuss CPAN, let’s talk about Perl for a moment.

Many of you faithful readers may have heard of the scripting language Perl but have no idea why you would ever need it. “What is Perl?” “What is it good for?” But the most important question you should ask is “What can Perl do for me?’

First let’s tackle “What is Perl?”

“What is Perl?”
From the Perl FAQ, which you can read at http://www.perldoc.com/perl5.6/pod/perlfaq1.html,

Perl is a high-level programming language with an eclectic heritage written by Larry Wall and a cast of thousands. It derives from the ubiquitous C programming language and to a lesser extent from sed, awk, the Unix shell, and at least a dozen other tools and languages. Perl’s process, file, and text manipulation facilities make it particularly well-suited for tasks involving quick prototyping, system utilities, software tools, system management tasks, database access, graphical programming, networking, and world wide web programming. These strengths make it especially popular with system administrators and CGI script authors, but mathematicians, geneticists, journalists, and even managers also use Perl. Maybe you should, too.

“What is it good for?”
Interesting, but does that mean?! What it means to you is that it’s a programming/scripting language that does a lot of text manipulations easily, is good for seeing how a finished product will look quickly, can do those drudgery chores that take 10 or more UN*X command line commands, can access and use your favorite databases, can draw pretty pictures, can do networking and works particularly well with the web.

Fantastic. It’s everything you ever wanted out of life and didn’t get. Well, ok, maybe not. It is, however, an extremely powerful language that can do a lot with just a little help from you and it doesn’t take forever to learn. It’s rather forgiving to beginners too (so sayeth the author who learned it in a day and has been using it nigh on 7 years now).

“What can Perl do for me?”
Ah my favorite question. New technology pops up all over the place. Some of it is very useful and sticks around a long, long time (like Perl) and some is short lived and doesn’t find much wide spread acceptance.

How can you tell which category Perl falls into? Well let’s look at it this way: it’s available for just about any platform you can imagine, it comes standard on every Linux and Mac OS X platform, you can extend it by writing your own specialized modules, there’re hundreds of modules out there that do things you wouldn’t think of trying in shell script or C, at least not without a few years of programming under your belt, it’s rather easy to get in the habit of, there’s no freakish compile step where something must be sacrificed and the proper deities invoked and oh yes, it’s completely 100% FREE. Only Wind*w$ chooses not to include it standard, go figure.

“Where can I get this ‘Perl’ thing? And where can I learn more about it?”
Well, Perl should already be on your server, if it’s relatively new, say within the last 10 years and it’s some flavor of Un*x or Linux (like my dear Mac OS X user friends).

From any command prompt, you should be able to ask:

[bigboy:bigboy/Users/me] me# which perl

and see something very much like:

/usr/bin/perl

Oh so I already have it? Yep. You should. Now if you’re one of the unfortunate masses on a computer running an inferior OS (which we shall not mention again, yea verily), then you can easily download a copy to play with from: http://www.perl.com/ (O’Reilly’s Perl.com site) or from your local CPAN archive site (http://www.cpan.org/).

All you need is some competence with a text editor (pick one, emacs, vi, etc.). Perl scripts are plain old ASCII text. Read some at the Perl site mentioned above for lots more info, goodies to try and so fantastic tutorials. Google is your friend. Try “learn Perl” as a search, you may be surprised at the number of sites willing to help you, faithful reader, learn the basics and subtleties of Perl.

CPAN
No faithful minion of Perl would be in armor without her link to http://www.cpan.org/, the Comprehensive Perl Archive Network. From here, all things Perl may be had (basically a repository of all the cool and useful as well as not so useful, addins and modules for Perl).

“Won’t I have to know how to compile *shudder* and install things? I didn’t ask for that much effort?”

Actually no. There’s a nifty little tool to help you do all that hard work with no serious effort on your part at all!

Continued in Part 2...