Perl: Another tool in your scripting arsenal

12Sep08

So I just came across a fairly good tutorial on Perl by Philip Paradis.

Perl’s a fun language. Before I came across Python (or indeed, before there was a Python), Perl ruled the scripting land. It was what people wrote a lot of Web applications in (now people predominantly use PHP, though I prefer Python) — hell, the University of Florida’s Web applications are still mainly written in Perl, like the ISIS system, which students use for everything from registering for classes to checking their grade point averages.

Perl’s roots are a bit more humble than Web apps, though; it started as a language for powerful text processing. It has a ton of built-in functionality for mangling and parsing text — splitting, searching through and otherwise wrangling any string of characters you can throw at it. That’s one of the areas that Paradis’ tutorial doesn’t cover very well (or at all), which might lead you to wonder why you’d use such a hideous-looking language.

I’ll admit, it is confusing to look at, but once you learn Perl’s regular expressions, you may understand why people prefer it to rip through text. It’s how I wrote the script that drives my crime map. From the regular expressions tutorial:

What is a regular expression? A regular expression is simply a string that describes a pattern. Patterns are in common use these days; examples are the patterns typed into a search engine to find web pages and the patterns used to list files in a directory, e.g., ls *.txt or dir *.*. In Perl, the patterns described by regular expressions are used to search strings, extract desired parts of strings, and to do search and replace operations.

String processing is still very much an integral part of the language, but with the Comprehensive Perl Archive Network, or CPAN, you can find a module to do just about anything your heart desires. Don’t believe me? A bit of random browsing lead me to a module to help calcluate baseball statistics.

In any case, I leave you with an image from my favorite Web comic, xkcd:

Now go check out that tutorial!

Advertisements


No Responses Yet to “Perl: Another tool in your scripting arsenal”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: