Utilities Guide: Chapter 1

Welcome to the Perl Resource Kit

What Comes with the Resource Kit?
How Can I Use the Resource Kit?
What You Should Know (And Where to Learn More)

The Perl Resource Kit, UNIX Edition, aims to be the ultimate companion to Perl--a scripting language written by Larry Wall, assisted by a cast of thousands. Perl brings together the best features of C, the Bourne Shell, and data manipulation utilities such as sed and awk. Its popularity and wide acceptance owes to the fact that you can master the core features quickly, and Perl's smooth learning curve means that you can learn as you go. You will often find that you learn more as your needs increase. As muscles tend to grow with use, so does your Perl knowledge.

Although one of Perl's strongest areas is processing text, it excels in other areas, such as system management, database access, and CGI development. You can also use it for graphical development, and it makes a great tool for quickly prototyping a system.

Perhaps you bought the Perl Resource Kit because you thought it would help you squeeze more power out of a language you already know well. Perhaps you were looking to get deeper insights into some of the hundreds of modules that are available for Perl. Maybe you just bought this because you couldn't bear to leave another Perl-related product stranded on the bookshelves of your favorite bookseller. Whatever your intentions for obtaining this kit were, I'm sure they were noble. To reward such pure motives, the Perl Resource Kit is going to do its best to meet your expectations.

Above all, the culture that surrounds Perl is very good at documenting its accomplishments. The abundance of online documentation is well-written, concise, and often delightfully up-to-date. However, there are a lot of choices available when you are attacking a project with Perl as your weapon. The hundreds of modules that are available can be quite overwhelming. Some modules overlap in very subtle ways, so it is not always easy to pick the right one without turning to sources of wisdom. Further, if you've come up against a programming problem that has not been addressed by one of these modules, what do you do when you need to code the solution yourself?

This is where the Perl Resource Kit comes in handy. The books that comprise it address these issues nicely. Programming with Perl Modules provides a tutorial introduction to using the most important Perl modules. This book also includes a chapter titled "Contributing to CPAN," which guides you in creating and deploying your own modules. The two-volume Perl Module Reference supplies complete documentation and reference for nearly 600 key Perl modules. This book, the Perl Utilities Guide, supplies instructions for installing the software on the CD-ROM and for installing modules both from the CD-ROM and from remote archive sites. Additionally, the Utilities Guide offers coverage of JPL, a Java/Perl interface written by Larry Wall. JPL allows you to create hybrid Java and Perl programs, leveraging the power of Perl for tasks such as network connectivity and string processing, while making the most of Java's graphical capabilities. JPL is available nowhere else but the Perl Resource Kit. JPL is included on the Resource Kit's CD-ROM along with other useful tools, information, and samples.

What Comes with the Resource Kit?

The Perl Resource Kit includes a CD-ROM filled with software and reference material. The material on the CD-ROM complements the four books included in the kit. To help you find your way around the Resource Kit, the following roadmap provides brief descriptions of the books and CD-ROM contents.

JPL

JPL is a Java/Perl interface written by Larry Wall exclusively for the Perl Resource Kit. JPL is not necessarily an acronym, but the J stands for Java, and the PL comes from .pl, a common file extension used for Perl scripts. JPL allows you to easily embed Perl within Java applications and provides the "glue" between the two languages. Using JPL, you can write embedded Perl methods that manipulate Java objects and primitive data types. Perl methods can accept Java objects and primitive values as arguments, and can also return objects and values to Java methods.

JPL can be used to build graphically rich, network-enabled applications that take advantage of the strengths of both languages. A number of example programs that showcase the wide possibilities available with JPL are developed in the Perl Utilities Guide. Many of these examples are included on the CD-ROM for you to use in your own JPL applications. Chapters 3 and 4 of this book cover the basic techniques of using JPL and walk through the examples.

The Graphical Setup Tool

The graphical setup tool lets you easily install the contents of the CD-ROM. It offers options to install a binary version of Perl and/or the source code for Perl, as well as the utilities and examples included with the Resource Kit. The setup tool also includes a facility for managing and installing unbundled Perl modules, which offers the ability to install modules from the CD as well as from remote archive sites. The remote retrieval capability makes it easy to ensure that the modules you have locally are the most current versions available.

CPAN Mirror

The Perl Resource Kit CD-ROM includes a mirror of CPAN (the Comprehensive Perl Archive Network). In the words of the CPAN welcome page, "CPAN aims to be The Perl archive, the only Perl archive you will ever need by definition: the C in CPAN obliges." In addition to the most recent Perl source code (as well as older versions), CPAN includes a vast collection of Perl modules. A module is a freely redistributable chunk of reusable code that can be easily imported into your Perl programs. In general, these modules are extremely easy to use, and often very well-documented. The graphical setup tool lets you search and copy modules from the CPAN mirror on the CD as well as from remote archive sites.

Programming with Perl Modules

Programming with Perl Modules includes an introduction to Perl modules, and tutorials for a number of the most popular and powerful modules. Building-block libraries, such as getopts, which allows you to parse command-line options are showcased, as well as high-level modules, such as GD, which offers you the ability to generate GIF images. In addition, Programming with Perl Modules includes tutorial coverage of database, network, and web modules, which exposes you to the fundamental building blocks of a web-based business solution. This book is an indispensable handbook for learning how to develop your own applications with Perl modules.

Perl Module Reference (Two Volumes)

The Perl Module Reference is a two-volume set that contains documentation for nearly 600 of the most popular Perl modules, organized by the same module categories used on CPAN itself. Not only will this reference enable you to find documentation on a module that you are using, but having the documentation available will help you decide if a given module is the right tool for the job before you install it.

Perl Utilities Guide

This book, the Perl Utilities Guide, provides step-by-step instructions on getting the most out of the CD-ROM. The graphical setup tool, which is available for Solaris and Linux users, is explained in detail. Also, this book explains how to build from source and install modules from the CD-ROM for users who cannot or who do not wish to use the graphical setup tool. And that's just Chapter 2!

The rest of the Utilities Guide is a comprehensive how-to and reference guide for building applets and applications that make use of JPL. Graphically rich sample programs give you hands-on practice using examples of some of the things that Perl is great for: data manipulation and network programming.

How Can I Use the Resource Kit?

Perl has been called the glue of the Internet. It's used in many places to connect applications to one another and has found one (among many) major niche: generating dynamic content for web sites. Of course, Perl is there for you when you have a multi-megabyte file that needs to be parsed, filed, sorted, indexed, briefed, debriefed, or numbered. So what can this resource kit do for you?

  • For any enterprise that has included Perl as part of its development strategy, this kit will be invaluable. The combined development expertise of the Perl Resource Kit authors has been distilled into the reference materials contained in the Kit. Not only are hundreds of the most popular modules identified and documented in the Perl Module Reference for your benefit, but a select number of these modules are given tutorial-level coverage in the Programming with Perl Modules book. Coupled with the complete mirror of CPAN, this makes for a very practical and indispensable reference.

  • Perl has already distinguished itself as the language of choice for Internet and intranet development. Everyone's seen web counters and guestbook scripts written in Perl, but did you know that Perl can be used to develop mission-critical Internet and intranet applications using a browser as a user-interface? The Programming with Perl Modules book includes conceptual coverage of the HTML and CGI modules, as well as the DBI. Combining these modules, you can build CGI-based applications that do almost everything that you can do with traditional client-server development tools. Enormously complex applications have been deployed in this fashion. The lesson learned is that Perl/CGI-based systems experience a number of benefits over traditional tools such as Powerbuilder, FoxPro, or Access. For one, there are marvelously few desktop support and configuration issues, since the only desktop component is the browser. Further, rollout of new versions is trivial: it can be as simple as changing a URL to point to the new version of the system. Also, Perl's object-oriented nature and wealth of available modules means that you don't need to reinvent the wheel each time you need a new feature. You can spend more time on user-visible features, and less time on developing interfaces to remote systems or coding up date parsing routines!

  • Perhaps you've built a web system using Perl, but you are tired of the limitations of the user interface available in HTML forms. For you, JPL represents an escape route. Through the magic of RMI (Remote Method Invocation), you can build Java applets that run on any desktop, but invoke Perl methods that belong to objects running on your remote server. Now that JavaSoft and the Object Management Group have agreed to guarantee interoperability between RMI and CORBA/IIOP (Common Object Request Broker Architecture/Internet Inter-ORB Protocol), you'll eventually be able to have your applications talk to objects all over the place! Using RMI and JPL is the topic of Chapter 5 of this book.

  • Although Perl is commonly thought of as a language for systems programming, web development, or raw text processing, it also makes a great companion to graphically rich languages such as Tk or Java. Using either Perl/Tk or JPL, you can build applications that make use of a sophisticated GUI interface. Both Perl/Tk and JPL are covered in the Resource Kit, and the sky's the limit as far as the sort of applications that can be developed with these tools. Do you need database access, graphing, and network connectivity? Build your front end with Perl/Tk or JPL, and drive the back end with the DBI for SQL access, GIFgraph for charts, and the libnet bundle for network connectivity. Oh, did you say it was a financial application that needs to connect to your company's ultra-secret pricing models that are packaged as a C library? Well, then just make use of Perl's XS interface to easily create an extension interface to your libraries!

What You Should Know (And Where to Learn More)

The Perl Resource Kit does not attempt to provide an introduction to Perl programming. Instead, it's a collection of tools that enables you to build on a solid foundation of mid-level Perl experience. If you're still using Perl 4.036 (or a much earlier version), you'll need to upgrade to the latest version to make use of the most current tools, including this Resource Kit. Fortunately, the Resource Kit includes the newest version of Perl. Here we cover some of the basic topics you should know as well as some background on resources for more information.

Basic Concepts and Features of Perl

To make the most efficient use of this Kit, you should have experience with some of the following areas of Perl programming. This information is a distillation of some of the features listed on the perl manpage, and is a list of features that are fundamental to understanding what goes into a module:

Data Structures

Perl offers you the ability to create scalar values that are references to variables and subroutines, which makes it possible to create a scalar value that is actually a reference to a scalar variable, hash, array, or even a chunk of code. Since arrays and hashes contain scalar values, each element of a hash or array can be a reference, making it possible to create arrays of arrays, arrays of hashes, arrays of code references, and so on. This feature is a critical part of Perl's object-oriented capabilities. There are a few manpages that are useful for learning more about data structures: perldata (Perl Data Structures), perlref (Perl References), perldsc (Perl Data Structures Cookbook), and perllol (Perl Data Structures: Lists of Lists). After you have installed Perl, you can view these manpages with the man or perldoc command, by issuing such commands as man perldata or perldoc perldata (or the name of the manpage you wish to see).

Perl Modules

Earlier versions of Perl allowed you to extend its functionality by importing library code or by building a new version of the Perl interpreter that was statically linked to a binary extension. The present version of Perl allows modules to be loaded dynamically at run-time. This includes modules written in Perl or binary modules compiled for your operating system. This feature, more than any other, has made it very easy for Perl developers to write reusable code. In addition to the documentation supplied in the Programming with Perl Modules book in this Resource Kit, the perlmod (Perl Modules: How They Work) and perlmodlib (Perl Modules: How To Write and Use) manpages are quite helpful.

Object-Orientation

Perl modules consist of one or more "packages" contained in a single file. A package offers a namespace that is independent from the default (main) namespace and from the namespace of other packages. With some very simple changes to the way you are used to programming, a package can easily be designed as a class. Most modules that are available are designed as classes. There are several good manpages that you can use if you are not familiar with Perl's object-oriented features, the most notable being perltoot, the Perl OO Tutorial. You may also consult perlobj (Perl Objects) and perlbot (Perl OO Tricks and Examples).

CPAN History

CPAN began as an idea offered by Jared Rhine to the perl-packrats mailing list on December 6, 1993. This message arrived on the mailing list only four days after the mailing list was created, at a time when the list's membership could have been counted on the fingers of two hands. The packrats had been discussing a strategy for archiving Perl sources in the wake of the accidental deletion of the Coombs archive, which was one of the leading archives of Perl scripts at the time. Jared's proposal suggested that this "comprehensive Perl archive" follow the structure of the CTAN project, "a collection of canonical sites for TeX."

One day after Jared's message was forwarded to the packrats list, Coombs was officially declared to be "no more a Perl archive." That very day, Bill Middleton sent a missive to the caretakers of the CTAN, seeking advice on creating and maintaining such an archive. Although a top-level organization of the CPAN was discussed, the idea slumbered until February 19, 1995, when Jarkko Hietaniemi posted a message, titled "CPAN idea still alive?" to the packrats mailing list. By June 5, after much discussion of how the CPAN should be organized, Jarkko announced a first cut of CPAN, which was located at ftp.funet.fi. The organization of the site barely resembled the present state; Perl 4 was still popular, so there was quite a bit of the site devoted to Perl 4 software. The Perl 5 extensions directory, possibly the closest thing to the modules directory of the current CPAN, included all of the extensions lumped into a single directory. It wasn't long before the suggestion was raised that these extensions be given subdirectories that corresponded to their package names.

On August 17, 1995, Andreas Koenig suggested an organization of the modules that led to the current organization of CPAN. The Perl 5 Module list, a master list of all freely available Perl modules, included a code for each author's name. Andreas suggested that the organization of the CPAN follow these author's names; one directory for each author, and all of that author's modules would be stored in the directory. On September 27, 1995, Andreas consolidated suggestions for CPAN's organization. Tim Bunce, then the maintainer of the Perl 5 Module List, suggested that the module categories in the module list be preserved, and this became the modules/by-category directory. The by-module directory was also adopted, and the by-author directory was chosen as the place where files would actually reside. The by-category and by-module directory contained symbolic links to the files in the by-author directory. This is the CPAN as it is known today; a massive (over 200 megabytes), distributed (mirrored by over 50 sites), well-organized archive of Perl materials. CPAN is accessible from the Tom Christiansen's perl.com multiplexor, at http://www.perl.com/CPAN.

CPAN Organization

The files in CPAN are organized in several ways. You can choose to browse CPAN by the module name, the author's name, or by the module category. Also, search engines are available that let you perform queries on the hundreds of modules available at CPAN. Finally, the Perl 5 Modules List is a widely available document that contains a list of all CPAN modules, as well as information about installing and using the modules. The Perl 5 Modules List is posted regularly to comp.lang.perl.announce. The Perl Resource Kit includes a CD-ROM with a complete copy of CPAN--thus, you can browse it or you can use the graphical setup tool (see Chapter 2) to locate and install modules.

You'll probably find browsing by module name and category to be the most useful. Browsing by module name is handy if you have become familiar with the modules that are available. Since related modules are often organized under the same package, if you are looking for something HTML-related, you'll probably browse within the directory set aside for HTML modules. Also, the module categories are organized at a very high level into more than twenty different groups. Browsing by module category can be very handy if you are not familiar with the available modules, or if you simply can't find the module you are looking for when you look in the usual places.

Imagine that you need to develop a script that retrieves email messages from a POP3 server. Of course, you'll write this script in Perl, there's no question about that. But you need to find a module that will help you interact with that POP3 server. Knowing that CPAN is the standard repository of all wisdom and knowledge, you truck on over to CPAN, using the URL:

http://www.perl.com/CPAN/modules/by-category

When you bring up the directory listing, you find one directory that catches your eye, 19_Mail_and_Usenet_News. Following that link, you find a directory known as Mail. Lo and behold, the Mail directory contains a module called POP3Client, which does exactly what you want!

Suppose now, three months later, you need to write a script that manipulates mail folders. Well, you remembered that the Mail module directory contained lots of neat stuff, so you head back to CPAN, but this time, you go directly to the Mail module directory with:

http://www.perl.com/CPAN/modules/by-module/Mail

Once you arrive at the Mail module directory, you find a package called MailFolder, which does exactly what you want. Of course, not all stories have such happy endings. Some end with you having to write the module you need, which can be a source of happiness in and of itself. In such cases, you'll find Programming with Perl Modules in this resource kit to be indispensable.

What If I Need Help?

If you can't find what you are looking for in the Resource Kit, your first point of outside help should be the Perl Resource Kit online site at http://perl.oreilly.com/. At this site you can find information on troubleshooting, technical support, ideas for using Perl, more tools and samples, and links to more information. You will also find a listing of other reference books on Perl and related topics that can help you solve the problem you are facing. The list of O'Reilly books on Perl is growing every month (to say nothing of the list of Java books). Check this site regularly for updated information, news, and help.

There is a wealth of online resources at your disposal, as well. The Perl Language Home page, at http://www.perl.com/, includes a comprehensive overview of all things Perl, as well as links to the various Perl FAQs (Frequently Asked Questions) other sites. If you have access to Usenet news, you will find the following newsgroups to be extremely useful sources of information:

comp.lang.perl.misc
general Perl language issues

comp.lang.perl.modules
discussions of Perl modules

comp.lang.perl.tk
issues related to Perl and Tk

However, since your question has probably already been answered, please check the FAQ first, and then an archive of Usenet news such as http://www.dejanews.com/ or http://www.altavista.digital.com/--you will most likely get the fastest answer this way. Failing that, you can try posting your question to one of the appropriate Perl newsgroups.

Return to Table of Contents

Copyright 1998, O'Reilly & Associates, Inc.