Perl Crash Course: Getting it Installed on…

In order to be able to learn Perl, you’ll have to first get it installed on your favorite Operating System. This chapter will show you how.

…Windows

When Perl users think Windows, one name comes to mind: http://www.ActiveState.com. ActiveState became famous for having the best Perl distribution for Windows around. The offer Perl for free, as well as Python and Tcl. ActiveState’s Perl distro comes with PPM – the Perl Package Manager, which has many precompiled modules for Windows and other architectures.

You can use PPM as a GUI or from the command line  – whichever way you feel more comfortable. We’ll see more about PPM later on.

…*nix

Although ActiveState became famous for its Windows distributions, it doesn’t stop there – you can also download Perl for Linux, Mac OS X, and Unix flavors AIX, Solaris, and HP-UX. And if you need to install it on any system not readily available, you can also get the source files for building. However, if you have a Unix or Linux distribution already running, then you probably already have Perl installed.

To see if you have Perl in your path, you can run which perl from the command line. It’s most likely under some default directory such as /bin or /usr/bin. If you’ve found it, you can run perl -v or perl -V for information regarding your distribution.

If you need a fresh install, for example in case you don’t have root access and need a newer perl release, you can compile one from source. The official Perl website is http://www.perl.org, and that’s where you’ll find the latest Perl release.

The steps for compiling Perl from source are out of the scope of this course, but it’s pretty straight forward – the configuration script is very verbose and it suggests the best values in case you don’t understand a certain question. Run ./configure, make, make test, make install and you’re done. Just have your favorite book handy, or another session to go through the documentation while the installation runs. It’s quite a lengthy process.

…Cygwin

“Cygwin is a Linux-like environment for Windows”. It’s an EXCELLENT tool for those who wish they had Linux or Unix but can’t. You can get it from their official site: http://www.cygwin.com. It installs using a Graphical User Interface, where you can select the Cygwin modules. Many of your most favorite *nix tools have been ported to Cygwin, and there are dozens of mirrors worldwide.

For many years, Perl was selected for installation by default. Recent releases, however, require that you manually select it. There are also some Perl modules available. Don’t forget also to select the tools you’ll need to build Perl modules: gcc, make, and their dependencies.

« Introduction to Perl | TOC | Variables and Data Structures »

Perl Crash Course: Introduction to Perl

Perl – the Practical Extraction and Report Language (or Pathologically Eclectict Rubbish Lister) was created by Larry Wall in the late 1980’s. It started as a combination of Larry’s favorite Unix tools such as sed, awk, and shell, and grew to be the best language for text manipulation.

I started learning Perl back in 1998 by myself. What made it possible for me to do that was that Perl scripts, like shell scripts, are not compiled binaries. You can open it with a (good) text editor and see exactly what the programmer did to make it work. Same thing with HTML, JavaScript, CSS, and all other democratic languages around. No reverse-engineering needed.

Speaking of Web technologies, Perl was considered SO GOOD with manipulating texts, that it was once the #1 language for CGIs. For those of you who don’t know, CGI stands for Common Gateway Interface and it was the way websites could show dynamic data back in the early days of the Internet. In fact, Perl was so popular with CGIs, that many people didn’t (and still don’t) know it could do anything else. On the contrary, although Perl has excellent Web modules such as Catalyst, Template::Toolkit, HTML::Mason, and so many others, it’s not my first choice for Web development (for reasons that are not in the scope of this course). However, I can’t live without it for anything else.

Perl is portable: you can write one script and run it in just about any Operating System that has a Perl interpreter installed. And you can find Perl interpreters for practically all the OS’s around.

Perl is fast: although the Perl interpreter needs to read, parse, compile, and run the script on every execution, it’s still VERY fast by any standard.

Perl gets faster: there are ways to bypass the first 3 stages of the Perl execution, either by using mod_perl for Apache, or by using the Perl Archive Toolkit, which gives you a precompiled (albeit potentially large) binary of your script.

Perl is Object Oriented: ok, that didn’t sound right. Perl can be used from either a procedural or an object oriented scope. In real world applications, you’re likely to mix both cases to suit your needs.

Perl is extremely high level: this means that given the statements in your script, you are likely to be able to read them as you would plain English. This was done on purpose, of course, given the fact that Larry Wall is a linguist.

Perl is free: you can download it with no cost from several distributors, install, and use for any purpose – commercial or otherwise and not have to worry about licensing.

Perl is free form: you can write the code practically in any way you like and get away with it. This is great as long as you keep in mind that writing good code also means writing clean code. You can seriously hurt your foot if you’re not careful. Obfuscation is only fun when it’s intentional.

I can go on forever telling you all that Perl can do, especially if I decide to talk about CPAN, the Comprehensive Perl Archive Network – a website with over 10,000 100,000 modules over 25k distributions for everything you can think of, from complex math and graphic manipulation to fooling around with the Klingon language. You can even use the Perl/Tk to create graphical user interfaces.

If what I said so far was enough to interest you to learn Perl, then keep on reading. There’s something to the language that feels almost addictive, if you don’t let all the non-initiated folks make up your mind against it…

« TOC | Getting it installed on… »

Perl Crash Course: TOC

It’s common, at least where I come from, for people to have a bad impression of Perl, or not to know anything about it at all. I believe it’s due to it being extremely high level and flexible, where almost every funny character in your keyboard has a function, and cases where you can actually write Poetry in it or have some masochistic fun with Obfuscation.

Since I’m the closest we have resembling a Perl SME in my team, I’ve been asked to put together a quick Perl Crash Course. I was going to prepare a presentation in PPT, but since I’m a disaster with that tool, I thought of doing it here and sharing it with everyone else. It’s also an opportunity for me to learn more…

So enough with the mumbo jumbo and let’s get to it!

Please note that this a is work in progress. Feel free to subscribe to my blog to get fresh updates.

Perl Crash Course TOC:

  1. Sticks and Stones
    1. Introduction to Perl
    2. Getting it Installed on…
      1. …Windows
      2. …*nix
      3. …Cygwin
    3. Variables and Data Structures
      1. Scalars
      2. Arrays and Lists
      3. Hashes
      4. References and Complex Data Structures (CDS)
      5. Gettin’ jiggy wit it
    4. Basic Regular Expressions
    5. Control Structures
    6. Basic I/O
    7. Subroutines
    8. File and directory tests and manipulation
  2. Even Apes Use Tools
    1. Packages, Namespaces, and Lexical scopes
    2. Pragmas, Perl Modules, and CPAN
    3. Object Oriented Perl
    4. Some handy modules
      1. Data::Dumper – Who’s afraid of CDS?
      2. Mime::Lite – e-mail anyone?
      3. DBI – The Database Interface
      4. Spreadsheet::* – Yes, we do Excel!
      5. DBD::Chart – Who would’ve thought…
  3. Homo Sapiens Sapiens
    1. Inter Process Communication
    2. eval this
    3. TMTOWTDI for control structures
    4. Tied Variables && MLDBM

If you have any comments or suggestions on the table of contents, please leave a comment. I’d like to add more stuff especially to the Homo Sapiens Sapiens section.