Hour 14. Using Modules

 <  Day Day Up  >  

What You'll Learn in This Hour:

  • Learn how to use modules in your Perl programs

  • Take a quick tour of some built-in modules

  • Review the list of the core modules distributed with Perl

Perl, as you've noticed, is an extremely flexible language. Not only does it deal with files, text, math, algorithms, and other issues normally found in any computer language; much of Perl is dedicated to special-purpose functions. Regular expressions are a core part of the language and are very important to the way that Perl is used, although many languages do just fine without them. Likewise, Perl's handling of external programs (backticks, pipes, and system from Hour 11, "System Interaction") is also extensive , whereas many languages don't handle them at all.

A temptation in designing a language is to include anything and everything useful in the core of the language itself. Being so inclusive can, however, create a language that is very large and difficult to use. For example, some language designers feel that support for access to the World Wide Web should be included in the core of the language. That's a useful feature, but not necessarily one that everyone needs. If the Web (using present protocols) is less important 10 years from now than it is today, a decision will have to be made to remove that support and a lot of already-written software will be broken.

For this reason, Perl has taken a different track. Starting with Perl 5, the language itself can be extended through the use of modules . Modules are collections of routines that allow you to extend Perl's reach. You'll find modules that add Web browsing, graphics, Windows Object Linking and Embedding (OLE), databases, and almost anything imaginable to Perl. Remember, however, that Perl does not need modules to run. It's completely functional without them.

By using modules, you can gain access to a large library of working code to help you write your programs. The last third of this book, in fact, is dedicated to writing CGI (Common Gateway Interface) programs using Perl modules.

At the time of this writing, more than 4000 modules are available, and more than two dozen are distributed with Perl. These modules, for the most part, can be freely redistributed. You can use them in your own programs for almost any purpose. Consequently, many difficult problems that you may encounter have already been solved for you; all you need to do is install the correct module and use it appropriately.

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net