Perl in a Nutshell

Perl in a Nutshell

5.0 2
by Nathan Patwardhan, Ellen Siever, Stephen Spainhour

View All Available Formats & Editions

This complete guide to the Perl programming language ranges widely through the Perl programmer's universe, gathering together in a convenient form a wealth of information about Perl itself and its application to CGI scripts, XML processing, network programming, database interaction, and graphical user interfaces. The book is an ideal reference for experienced Perl


This complete guide to the Perl programming language ranges widely through the Perl programmer's universe, gathering together in a convenient form a wealth of information about Perl itself and its application to CGI scripts, XML processing, network programming, database interaction, and graphical user interfaces. The book is an ideal reference for experienced Perl programmers and beginners alike.With more than a million dedicated programmers, Perl is proving to be the best language for the latest trends in computing and business, including network programming and the ability to create and manage web sites. It's a language that every Unix system administrator and serious web developer needs to know. In the past few years, Perl has found its way into complex web applications of multinational banks, the U.S. Federal Reserve, and hundreds of large corporations.In this second edition, Perl in a Nutshell has been expanded to include coverage of Perl 5.8, with information on Unicode processing in Perl, new functions and modules that have been added to the core language, and up-to-date details on running Perl on the Win32 platform. The book also covers Perl modules for recent technologies such as XML and SOAP.Here are just some of the topics contained in this book:

  • Basic Perl reference
  • Quick reference to built-in functions and standard modules
  • and mod_perl
  • XML::* modules
  • DBI, the database-independent API for Perl
  • Sockets programming
  • LWP, the library for Web programming in Perl
  • Network programming with the Net modules
  • Perl/Tk, the Tk extension to Perl for graphical interfaces
  • Modules for interfacing with Win32 systems
As part of the successful "in a Nutshell" book series from O'Reilly & Associates, Perl in a Nutshell is for readers who want a single reference for all their needs."In a nutshell, Perl is designed to make the easy jobs easy, without making the hard jobs impossible."— Larry Wall, creator of Perl

Editorial Reviews
The Barnes & Noble Review
Perl and O’Reilly go together like peanut butter and jelly. Perl’s creator, Larry Wall, even works there, guiding the future of the language. Then, of course, there’s O’Reilly’s “camel book,” Programming Perl, one of the world’s few truly legendary computer books. So if you’re looking for an authoritative Perl language reference, you’d expect O’Reilly to offer a great one. And they do.

Perl in a Nutshell, Second Edition combines a complete overview of working with Perl and a thorough reference. If you’ve fooled with Perl (or even another scripting language) even a little, the book’s introductory tutorials will be all you’ll need to move forward. If you’re an experienced Perlmonger, they’re a perfect refresher.

It’s all here, from installation through debugging and Win32 support. The heart of the book: coverage of Perl modules that extend the language in virtually every imaginable direction. Perl in a Nutshell, Second Edition covers virtually all the most widely used modules in the most popular areas of Perl development:, mod_perl for Apache, DBI for connecting with your friendly neighborhood database; new tools for XML and SOAP processing; network, web, and email programming modules; and more. It’s an immense, well-organized resource for every Perl developer. (Bill Camarda)

Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.

Product Details

O'Reilly Media, Incorporated
Publication date:
In a Nutshell (O'Reilly) Series
Edition description:
Second Edition
Sales rank:
Product dimensions:
6.04(w) x 9.00(h) x 1.39(d)

Read an Excerpt

Chapter 2: Installing Perl The CPAN Architecture

CPAN represents the development interests of a cross-section of the Perl community. It contains Perl utilities, modules, documentation, and (of course) the Perl distribution itself CPAN was created by Jarkko Hietaniemi and Andreas Ming.

The home system for CPAN is, but CPAN is also mirrored on many other sites around the globe. This ensures that anyone with an Internet connection can have reliable access to CPAN's contents at any time. Since the structure of all CPAN sites is the same, a user searching for the current version of, Perl. can be sure that the latest.tar.gz file is the same on every site.

The easiest way to access CPAN is to utilize the CPAN multiplex service at The multiplexor tries to connect you to a local, fast machine on a large bandwidth hub. To use the multiplexor, go to the multiplexor will, automatically route you to a site based on your domain.

If you prefer, you can choose a particular CPAN site, instead of letting the multiplexor choose one for you. To do that, go to the URL (no wailing slash). When you omit the trailing slash, the CPAN multiplexor presents a menu of CPAN mirrors from which you select the one you want. It remembers your choice next time.

To get the current Perl distribution, click on latest.tar.gz. For ports to other systems, click on ports. The modules link is the one, you want if you're looking for a Perl module- from there you can get a full list of the modules, or you can access the modules directly by author, by CPAN category, or by module. (The section "Getting and Installing Modules" later in this chapter talks about installing modules. Click on doc for Perl documentation, FAQs, etc.

Installing Perl

Most likely your system administrator is responsible for installing and upgrading Perl. But if you are the system administrator, or you want to install Perl on your own system, sooner or later you will find yourself. installing a new version of Perl.

If you have been running Perl, and you are now going to install Perl 5.005, you need to be aware that it 'is not binary compatible with older versions. This means that you must rebuild and reinstall any dynamically loaded extensions that you built under earlier versions.

Specific installation instructions come in the README and 17VSTALL files of the Perl distribution kit. If. you don't already have the Perl distribution, you can download it from CPAN-the latest Unix distribution is in latest.tar.gz. The information in this section is an overview of the installation process. The gory details are in the INSTALL file, which you should look at before starting, especially if you haven't done an installation before. Note that operating systems other than Unix may have special instructions; if so, follow those instructions instead of what's in this section or in INSTALL Look for a file named READMExxx, where xxx is your OS name.

In addition to Perl itself, the standard distribution includes a set of core modules that are automatically installed with Perl. See the "Getting and Installing Modules" section later in this chapter for how to install modules that are not bundled with Perl; Chapter 8, Standard Modules, describes the standard modules in, some detail.

Installing on Unix

Typically, you'll get the Perl kit packed as either a tar file or as a set of shar (shell archive) scripts; in either case, the file will be in a compressed format. if you got your version of Perl directly from CPAN, it is probably in "tar-gzipped," format; tar and gzip are popular Unix data-archiving formats. In any case, once you've downloaded the distribution, you need to uncompress and unpack it. The filename indicates what kind of compression was used. A Z extension indicates you need to uncompress the file first, while a gz extension indicates you need to gunzip the file. You then unpack the file as appropriate, read the README and INSTALL files, and run a massive shell script called Configure, which tries to figure out everything about your system and creates the file to store the information. After this is done, you do a series of "makes" to find header file dependencies, to compile Perl (and a2p, which translates awk scripts to Perl), to run regression tests, and to install Perl in your system directories.

One common problem is not making sure that Perl is linked against all the libraries it needs to build correctly. Also, you should say "yes" when Configure asks if you want dynamic loading, if your system supports it. Otherwise, you won't be able to install modules that use XS, which provides an interface between Perl and C.

If you are running Linux, some Linux distributions might not include a complete MakeMaker, which you need for installing modules. To be safe, you should make sure everything is there; one Way to do that is to check the file. If MakeMaker is not correctly installed, you might need to build Perl yourself.

It's possible you'll get a compiled (binary) copy of Perl, rather than the source. in that case, make sure you get suidperl, a2p, s2p, and the Perl library routines. Install these files in the directories that your version was compiled for. Note that binary distributions of Perl are made available because they're handy, not because you are restricted from getting the source and compiling it yourself. The people who give you the binary distribution ought to provide you with some form of access to the source, if only a pointer to where they got the source. See the Copying file in the distribution for more information.

Perl examples

The Perl source distribution comes with some sample scripts in the eg/ subdirectory. Feel free to browse among them and use them. They are not installed automatically, however, so you need to copy them to the appropriate directory and possibly fix the #1 line to point to the right interpreter.

The files in the. t/ and lib/ subdirectories, although arcane in spots, can also serve as examples.


Since Perl is constantly being honed and improved, patches are sometimes made available through CPAN. Your distribution is likely to have had most of the patches applied already-run perl -v to check the patch level of your distribution. Patches are sent out with complete instructions on how to apply them using patch, which is available from the GNU project.

Installing on Win32

You need to obtain and install a copy of Perl yourself, unless you have had the good fortune of having a system administrator install Perl on your system.

For Perl 5.004, there are two different distributions for Win32 systems. The first is Perl for Win32, which was developed by ActiveState Tool Corporation. The second is actually the standard Perl distribution-Perl 5.004 added support for Win32 systems to the standard Perl distribution. In Perl 5.004, the two versions are largely compatible, with some of the Perl 5.004, code being based on the ActiveState port. However, there are also some differences: using either the ISAPI version of Perl or PerlScript with 5.004 requires the ActiveState distribution. On the other hand, the Win32 ports of mod_perl or Perl/Tk require the "native" (or standard) version of 5.004.

With Perl 5.005, this scenario has changed, and the two versions have been merged. if you look on CPAN, you'll see that there still seem to be two versions the ActiveState distribution, now known as ActivePerl, an& the standard distribution. The difference is that they are now based on the same source code. Get ActivePerl if you want to install from a binary distribution or get the standard distribution to build Perl from the source code.


The canonical source for the ActivePerl distribution at the time of this writing is at Included in the distribution are:
  • Perl for Win32
  • Binary for the core Perl distribution
  • Perl for ISAPI
  • IIS plug-in for use with ISAPI-compliant web servers
  • PerlScript
  • ActiveX scripting engine
  • Perl Package Manager

Manager for Perl modules and extensions

The ActivePerl binary comes as a self-extracting executable that uses the standard Win32 InstallShield setup wizard to guide you through the installation process. By default, Perl is installed into the directory C:\perl\version, where version is the current version number (e.g., 5.005). Unless you choose to customize your setup, the default installation does not modify your registry other than to add an entry so you can uninstall Perl. For information on customizing your installation, see the Win32 FAQ on the ActiveState web site. The installation also associates the We extension .pl with Perl and adds the directory into which you installed Perl to your PATH environment variable.

Standard Perl distribution

The standard Perl distribution is available from, CPAN, where you'll find binary and source distributions for Perl 5.004 for both Windows NT and Windows 95, and the source distribution for Perl 5.005. You can get the binary for Perl 5.004 as either a .tar.gz file or a zip file. The source distributions come as targz files, which you can extract using a. utility that -supports gzip files, tar files, and long filenames. Ports of both GNU gzip and tar are available for the various Win32 platforms, or you can use a graphical zip archive program such as WinZip. Make sure you preserve the directory structure when you unpack the distribution. . . .

Meet the Author

Nathan Patwardhan is an active Perl Monger and has extensive experience in system administration and application development for web based corporations. He is also the co-author of the first edition of Perl in a Nutshell and Programming with Perl Modules (distributed with the O'Reilly Perl Resource Kit).

Ellen Siever is a writer and editor specializing in Linux and other open source topics. In addition to Linux in a Nutshell, she coauthored Perl in a Nutshell. She is a long-time Linux and Unix user, and was a programmer for many years until she decided that writing about computers was more fun.

Stephen Spainhour co-authored Webmaster in a Nutshell, Perl in a Nutshell, 1st Edition, and contributed to many other OReilly titles. He is an avid fan of professional tennis, and when hes not checking for tennis scores on the Web, he enjoys cooking, electronic music, troubleshooting his home-built PC, and watching too much television.

Customer Reviews

Average Review:

Write a Review

and post it to your social network


Most Helpful Customer Reviews

See all customer reviews >

Perl in a Nutshell 5 out of 5 based on 0 ratings. 2 reviews.
Anonymous More than 1 year ago
Anonymous More than 1 year ago