Perl in a Nutshell: A Desktop Quick Reference

Perl in a Nutshell: A Desktop Quick Reference

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

See more details below

Overview

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

  • CGI.pm 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

Read More

Product Details

ISBN-13:
9781449378820
Publisher:
O'Reilly Media, Incorporated
Publication date:
06/03/2002
Series:
In a Nutshell (O'Reilly)
Sold by:
Barnes & Noble
Format:
NOOK Book
Pages:
762
File size:
4 MB

Meet the Author


Ellen Siever is a writer at O'Reilly & Associates, where she has also been a production editor and tools specialist. Before coming to O'Reilly, she was a programmer for many years in the Boston area. In addition to computers, her interests include her family, travel (especially if it's in the Southwest),. and photography.

Stephen Spainhour is a writer for O'Reilly & Associates. He has contributed to many O'Reilly tides. He is an avid fan of professional tennis (and terrible player), and when he's not checking for tennis scores on the web, he enjoys cooking, electronic music, and watching lots of television.

Nathan Patwardhan is a consultant with Collective Technologies where he works with Unix and programming languages like C and Perl. Nathan has been interested in Perl for several years, his most recent efforts being centered around Perl for Win32. In his free time, he enjoys Etch-A-Sketch and desserts by Swanson. You might occasionally find Nathan on EFNet's #perl or #helmet or checking in on one of the Usenet groups: comp.dang.perl.misc or comp.lang.perl.moderated.

Read More

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 funet.fi, 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 www.perl.com. The multiplexor tries to connect you to a local, fast machine on a large bandwidth hub. To use the multiplexor, go to http://www.perl.com/CPAN 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 http://www.perl.com/CPAN (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 Config.pm 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 Config.pm 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.

Patches

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.

ActivePerl

The canonical source for the ActivePerl distribution at the time of this writing is at http://www.activestate.com. 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. . . .

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >