EarthWeb   

HomeAccount InfoLoginSearchMy ITKnowledgeFAQSitemapContact Us
     

   
  All ITKnowledge
  Source Code

  Search Tips
  Advanced Search
   
  

  

Perl Core Language Little Black Book Perl Core Language Little Black Book
by Steven Holzner
The Coriolis Group
ISBN: 1576104265   Pub Date: 03/01/99
  Buy ItBookmark It

Search this book:
 
Previous Table of Contents Next


Introduction

This book is designed to give you all that you need to become a Perl programmer, and that’s saying a lot. Perl is no ordinary programming language—it inspires devotion, passion, exaltation, and eccentricity, not to mention exasperation and frustration. It’s more than a programming language—it’s a cause, the stuff of programmer poets and fanatics. Perl may be complex and arcane at times, it may be even be confusing and inconsistent, but to a true devotee, there’s no other way to go. You’ll see what I mean as you read this book.

In its 12 year reign, the Practical Extraction and Reporting Language (also called, often by the same people, the Pathologically Eclectic Rubbish Lister) has become the object of much affection. Remarkable numbers of people devote remarkable numbers of volunteer hours to using, improving, and disseminating it. I started working with Perl years before I thought of writing a book on it. Maybe the Perl way of doing things will turn you into a fanatic, too.

What’s In This Book

This book gives you not only the full Perl syntax, but also a realistic snapshot of Perl and how it’s used today. For example, you’ll find Perl just about anywhere you look on the Internet, so there’s a lot of real-world CGI coverage here. Another popular modern topic is the connection between Perl and Tcl/Tk, which lets you display windows, buttons, menus, and more using Perl, and that’s another topic in this book. There are other real-world topics, like connecting Perl to databases, to Windows OLE automation servers, to other processes, and so on, and they’re here too. All in all, this book is designed to give you a good picture of what’s going on in Perl today.

There are also many additions to Perl 5 that you’ll see in this book, such as writing more readable Perl code, BEGIN and END blocks in packages, POSIX compliance, object-oriented programming, arbitrarily nested data structures, lexical scoping, enhanced use of modules, and other topics. Version 5 was a big change for Perl, and it’s the version this book was written on.

This book is divided into separate, easily accessible topics—nearly 500 of them—each of which addresses a separate programming issue. Here are some of those topics:

  Perl 5 syntax: statements and declarations
  Running Perl scripts interactively
  Text I/O
  Creating scalar variables
  Scalar and list contexts
  Creating arrays and hashes
  Loops and conditionals
  Typeglobs and symbol tables
  Perl operators
  Regular expressions and string handling
  Creating subroutines
  Lexically scoped variables
  Temporary variables
  Persistent (static) variables
  Recursive subroutines
  Anonymous arrays, hashes, and subroutines
  Perl references
  Symbolic references
  Persistent scope closures
  Function templates
  Perl special variables
  Perl’s built-in functions
  POSIX functions
  Perl formats
  Interprocess communication
  Win32 OLE automation
  File handling
  DBM database files
  Locking files
  Perl directory operators
  Benchmark tests
  Locale-sensitive operations
  Safe code compartments
  Perl/Tk: Using the Tk toolkit
  Complex records
  Arrays of arrays, hashes of hashes, arrays of hashes, and hashes of arrays
  Linked lists and ring buffers
  Perl packages
  Package constructors and destructors
  Splitting a package across file boundaries
  Perl modules
  Exporting symbols from modules
  Autoloading module subroutines
  Perl classes
  Class constructors
  Perl objects
  Class methods
  Instance variables and class variables
  Class inheritance
  Multiple inheritance
  Tying scalars, arrays, and hashes
  Trapping runtime errors
  The Perl Debugger
  Perlscript
  Common Gateway Interface (CGI) programming
  Creating and using HTML controls from CGI
  CGI security
  Tainting and untainting data
  Giving a CGI script more privileges
  Creating a Web counter
  Creating a guest book
  Emailing from a CGI script
  Creating a multiuser chat application
  Multiuser security issues
  Handling denial of service attacks
  Clearing refreshed HTML controls
  Creating cookies
  Storing data in Web pages between calls to a script

There are one or two conventions that I’ll use in this book that you should be aware of. When a particular line of code needs to be pointed out, I’ll shade it this way:


$text = “Hello!\n”;

print $text;

And to set the output of a script apart from the script itself, I’ll set it in lightface italics:


$text = “Hello!\n”;

print $text;



Hello

What You’ll Need

I use Perl version 5.005 in this book. Perl is free, all you have to do is to download it and install it—see the topic “Getting And Installing Perl” in Chapter 1. If you’re on a multiuser system, your system may already have Perl installed; to check, try this command at the command-line prompt, which will give you the Perl version:


perl -v


TIP:  Two more things when it comes to running Perl itself—I recommend that you use the -w command-line switch so that Perl will display warnings as needed when you run your scripts (Perl may make this the default one day), and also put the compiler directive use strict in your scripts so that Perl requires variables and other symbols to be declared. Doing these two things can save you a surprising amount of debugging time.

You’ll also need some way of creating Perl scripts. Such scripts are just plain text files filled with Perl statements and declarations. To create a Perl script, you should have an editor program that can save files in plain text format. See the topic “Writing Perl Scripts” in Chapter 1 for more information.

One thing you won’t need is a deep knowledge of Perl’s original operating system, Unix. Although many Perl books seem to take it for granted that you’re a Unix programmer, that’s not the case here. Perl has moved beyond Unix, and it’s time Perl books recognize that fact.

Other Resources

There are other Perl resources that can be of assistance with Perl. Perl comes with a lot of useful documentation. On systems like Windows, that documentation is stored in linked HTML pages. On multi-user systems, you can usually access that documentation through system commands (such as the Unix man command).

There are also a number of Usenet groups for Perl programmers:

  comp.lang.perl.announce—A low-traffic group.
  comp.lang.perl.misc—A high-traffic site that also posts a Perl FAQ.
  comp.lang.perl.modules—All about creating modules and reusing your own or someone else’s code.
  comp.lang.perl.tk—About the connection between Perl and the Tcl language’s Tk toolkit. The Tk toolkit supports many visual controls like buttons, menus, and so on that you can use with Perl, and it’s become pretty popular.

If you’re interested in CGI programming, take a look at this group:

  comp.infosystems.www.authoring.cgi—It doesn’t have Perl in the name, but it’s a good place to talk with others about Perl CGI programming.

There are also many, many Web pages out there on Perl (a random Web search turns up a mere 1,527,903 pages mentioning Perl):

  The Perl homepage is www.perl.com and you can find source code and Perl ports for various operating systems, documentation, modules, bug reports, and a Perl frequently asked questions list there. (The FAQ is at www.perl.com/perl/faq.)
  To get Perl, Perl modules, Perl extensions, and tons of other Perl things, look at the Comprehensive Perl Archive Network, CPAN, at www.cpan.org or at www.perl.com/CPAN-local/CPAN.html. This is the huge, all-in-one source for just about anything having to do with Perl. If you browse through CPAN, you’re sure to see lots of code you want, from Perl language extensions to image handling, from Internet modules to database interfaces.
  The Perl Institute at www.perl.org is a non-profit organization dedicated, in its own words, “to keeping Perl available, usable, and free for all.” The Institute is a mainstay of the Perl community, providing a great deal of communication between Perl devotees.
  The Perl language page is at www.perl.com/perl/ (which takes you to language.perl.com), and it includes Perl overviews, news, resource lists, and software. It also includes a list of Perl mailing lists.
  Many other sites having to do with special Perl interests like security, CGI programming, and more—just search the Web if you want to be overwhelmed.

There’s also the Perl journal, a magazine sent out four times a year. For more information, take a look at orwant.www.media.mit.edu/the_perl_journal/.

And that’s all the introduction needed—now it’s time to get into Perl, starting with Chapter 1.


Previous Table of Contents Next

Copyright © The Coriolis Group, Inc.

HomeAccount InfoSubscribeLoginSearchMy ITKnowledgeFAQSitemapContact Us
Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.