Home > Store

Modern Perl Programming

Register your product to gain access to bonus material or receive a coupon.

Modern Perl Programming


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2002
  • Dimensions: 7" x 9-1/4"
  • Pages: 368
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-008965-6
  • ISBN-13: 978-0-13-008965-6

Supercharged Perl programming for every developer, sysadmin, and Web professional.

  • In-depth coverage of references—the cornerstone of advanced Perl programming
  • Complete application examples, not just code snippets
  • CGI, networking, GUIs, and object development
  • Enterprise database integration applicable to all databases including Oracle and Sybase

Modern Perl Programming will help you master Perl's most robust, powerful features—so you can make the most of the language whether you're a beginner or an experienced scripter. Michael Saltzman starts with a rapid-fire Perl tutorial and refresher. Then, using actual applications—not just code snippets—he presents expert guidance on the Perl features that deliver the most power, productivity, and efficiency.

Coverage includes:

  • Practical coverage of data types, I/O, control structures, and operators
  • Making the most of associative arrays, hash tables, and regular expressions
  • Building your own subroutines
  • Developing Web-based CGI and network applications
  • Example-rich coverage of references (pointers)-the cornerstone of advanced Perl development
  • Object-oriented programming, data structures, and advanced GUI development
  • Integrating with enterprise-class databases: detailed examples applicable to Oracle and Sybase and other databases
  • Debugging Perl applications

Includes extensive downloadable library of code samples! You won't just get results fast: You'll get great results fast—robust, maintainable, industrial-strength Perl for even the most challenging environments.


Source Code

The EXAMPLES and SOLUTIONS directories support the Prentice Hall book MODERN PERL PROGRAMMING by Michael Saltzman.

Each directory contains 16 sub directories, 1, 2, 3.... 16 which represent the chapters in the book.

EXAMPLES\1 contains coded examples in the 1st chapter of the book.
EXAMPLES\2 contains coded examples in the 2nd chapter of the book.

SOLUTIONS\1 contains the solutions to the labs for chapter 1.
SOLUTIONS\2 contains the solutions to the labs for chapter 2.

The file labfiles.zip contains the EXAMPLES and SOLUTIONS directories in a zip archive.

Sample Content

Online Sample Chapter

Introducing Perl

Table of Contents

What Is Perl?

Why program in Perl?

Why did I write this book?

Who should read this book?

Overview of the Book.

Chapter Summaries

1. A Tutorial Introduction to Perl.

Getting Started. Perl Variables. Control Flow Constructs. Altering Loop Control Flow. A Few Special Perl Variables. Regular Expressions. Writing Your Own Functions. Exercises.

2. Input and Output in Perl.

Filehandles. Creating Your Own Filehandles. File Operators. The stat Function. Other Filehandles. Exercises.

3. Operators in Perl.

Perl Operators. Exercises.

4. Arrays and Array Functions.

Introduction. The @ARGV Array. Array Functions. Exercises.

5. Hashes.

Introduction. Sorting Hashes. Hash Solutions to Common Problems. Built-in Associative Arrays. Reading from a File into a Hash. Exercises.

6. Regular Expressions.

Introduction. The Match Operator. Regular Expression Metacharacters. Anchoring Patterns. Remembering Parts of Matches. Greedy Regular Expressions. Substitutions. Backtracking. The tr Operator. Exercises.

7. Subprograms.

Introduction. Passing Arguments to Subroutines. Returning Values from Subroutines. Perl Libraries. The Perl Standard Library. Packages. Predefined Subroutines. Exercises.

8. Generating Reports in Perl.

Introduction. Format. Top-of-page formatting. The select Function. Bottom-of-Page Formatting. Exercises.

9. Accessing System Resources.

Introduction. File and Directory System Calls. Process Creation. Updating Files. Exercises.

10. Perl References.

Introduction. Anonymous References. Complex Data Structures. Collections of Records. Exercises.

11. Object-Oriented Programming.

Introduction. The Vocabulary of Object Orientation. Defining and Using Objects. Inheritance. Exercises.

12. Client/Server Applications.

Introduction. Writing Clients. Writing Servers. Iterative Servers. Exercises.

13. CGI Programming with Perl.

Introduction. HTML and Forms. Relationship between Server and CGI Script. cgi-lib.pl and cgi.pm. CGI Scripts and Databases. Exercises.

14. Graphical User Interfaces with the Tk.pm Module.

Introduction. Geometry Management. Buttons. Other Widgets. Frames. Binding. Exercise.

15. Accessing Real Databases in Perl.

Introduction. A Review of SQL and Relational Databases. Accessing a Database from Perl. Adding a Graphical Front-End. Accessing a Real Database via a Web Form.

16. Debugging Perl Scripts.

Introduction. Using the print Function. Command-Line Options. Executing Portions of Your Code. Quoting. Useful Perl Modules. The Perl Debugger. Useful Perl Functions.




Welcome to the world of Perl programming. I know that few of you enjoy reading the preface, but it may help to at least browse through it to make the reading of the actual text a little easier. In this section I will tell you a little about Perl and a lot about conventions used in this book. But first, I have a few questions to answer.

What Is Perl?

Perl is a programming language that was created by Larry Wall in the early 1980s. The language has gained widespread popularity over the last few decades. In the beginning, Perl was used by a small group of Unix system administrators who needed a language, superior to the Unix shell, to do various system administration tasks. With the exponential growth of the Internet and the popularity of the World Wide Web's Common Gateway Interface (CGI) programming paradigm, the number of Perl programmers has also grown exponentially.

Why program in Perl?

Being familiar with many programming languages, I'm in a good position to judge them. I have had my favorite languages throughout the years: Fortran, PL/1, C, C++, Java, and of course, Perl. Too many people argue about which language is the best. No language can be all things to all people. Each language has its strengths and weaknesses. However, no language that I know has the expressive capability and ease of use of Perl. You, of course, can decide for yourself when you finish reading this book.

Why did I write this book?

I have been an instructor of computer programming languages for more than three decades. In that time, I have had the occasion to learn many languages. My typical approach would be to buy a book on the subject, plow through it, and write as many programs as I could to test out various features of the language.

I'm very critical of textbooks. Most of the textbooks that I've read never seem to be at the correct level. Half of them seemed too elementary; the other half seemed too advanced. I always wanted one that was right in the middle. I've tried to write this book for the intermediate audience because I think I can save people in that category a lot of time and research.

Who should read this book?

This is a book about Perl programming, so anybody who is interested in writing Perl programs should read this book. Since Perl is a programming language, you would think this means only programmers should read it. Currently, however, there is a blur over who is a programmer. Many Web-sters who maintain Web pages also write CGI scripts. System administrators need to write scripts to support users. Managers periodically want to write scripts to create reports for various staff members above and below them in the corporate hierarchy. All these groups would profit from reading this book.

Overview of the Book

The book is organized in three sections: beginning, intermediate, and advanced. In the beginning section, you will see topics such as: input and output, operators, arrays, control structures, and data types. In the intermediate section, you will see topics such as: associative arrays, regular expressions, subroutines, report writing, and accessing system resources. The advanced section includes topics such as: references, object-oriented programming, client/server programming, CGI programming, graphical user interfaces (GUIs) with the Tk module, accessing real databases in Perl, and debugging.

Chapter Summaries

Chapter 1: A Perl Tutorial

— demonstrates many fundamental Perl features so that you can start writing Perl programs quickly. Subsequent chapters will drill more deeply into each of the topics presented here.

Chapter 2: Simple I/O

— looks more deeply into reading and writing files. Some of Perl's operators for determining the type of a file are explored. Finally, this chapter looks at how you can determine information about files.

Chapter 3: Perl Operators

— examines the Perl operators. A Perl expression is a syntactically correct combination of operators and operands. Perl has a plethora of operators. Many of them originated with the C language and some of them are particular to Perl. In this chapter, we will explore all of the operators, including those used for bit manipulation, string manipulation, and regular expressions.

Chapter 4: Arrays and Array Functions

— takes an in-depth look at arrays in Perl. All programming languages use arrays heavily and Perl is no exception. However, you will see that Perl arrays are dynamic and are supported by a wide variety of functions. We will take a look at some of the nice features of Perl arrays. Finally, we will look at many of the more common array functions used by Perl programmers.

Chapter 5: Hashes

— looks at a common scenario in programming languages: paired data. Associative arrays, also called hashes, provide an efficient way to search for values by their keys. In this chapter, we will show how hashes may be used to efficiently solve a wide variety of commonly encountered problems.

Chapter 6: Regular Expressions

— refers to patterns that are expressed with characters armed with special meanings. These patterns may be compared to strings to see if the strings match the patterns. These regular expressions make it easy for Perl to validate data, make substitutions, or pick out portions of a match.

Chapter 7: Subprograms

— investigates the wide gamut of possibilities when you write your own functions. This chapter examines all of the principles having to do with subroutines in Perl. Some languages refer to these blocks as functions, while others refer to them as subroutines, and still others refer to them as procedures. In Perl, they are referred to as either subroutines or functions. Perl does not differentiate between these two terms.

Chapter 8: Generating Reports in Perl

— demonstrates Perl's report writing capabilities. Reports are typically written by system administrators to summarize user and file activity. You can have Perl automatically generate headers and body formats. This chapter gives the details of the rudimentary report writing capabilities of Perl.

Chapter 9: Accessing System Resources

— reveals the many system calls that are available via Perl. There is a strong Unix flavor to these functions. However, many of them have been implemented on Windows so that they have a consistent behavior regardless of the operating system.

Chapter 10: Perl References

— moves the reader along into slightly advanced concepts. This chapter concentrates on a thorough treatment of references, Perl's version of pointers. References are used for almost all advanced Perl topics.

Chapter 11: Object-Oriented Programming

— gives the details on how to write Perl programs that use objects and methods. This important chapter is the basis of many of the Perl modules found at various Perl repositories on the Internet.

Chapter 12: Client/Server Applications

— explores the possibilities of writing network applications with Perl. After reviewing some networking fundamentals, we'll give some examples of writing clients that connect to real servers. Then we will write a few servers of our own.

Chapter 13: CGI Applications

— explores the topics of writing back-end programs invoked by Web servers to process front-end fill-in forms. This style of programming, called CGI scripting, is largely responsible for the exponential growth of Perl.

Chapter 14: Graphical User Interfaces with the Tk.pm Module

— gives a great many details about writing GUIs in Perl using the Tk.pm module. This is a great undertaking as this is a vast body of knowledge. This chapter demonstrates many Tk capabilities, but at a high level. All the methods in this section take many options. We will only show a few for each and leave the rest for a book that specializes in writing GUIs in Perl using the Tk module. Our approach in this section will be to introduce a few widgets and build a program in pieces. At the conclusion of this section, we will have built a GUI with an application behind it.

Chapter 15: Accessing Real Databases in Perl

— shows how to integrate SQL commands within your Perl scripts so that real databases may be accessed. To remain vendor-neutral, we will use the MySQL database, which can be downloaded at www.mysql.com. With this database, we will demonstrate the principles of accessing all databases in Perl, regardless of whether the actual database is Oracle, Sybase, Access, etc.

Chapter 16: Debugging Perl Scripts

— explores many of the possibilities of debugging your Perl code. Debugging a piece of software is a difficult task in any programming language. Since Perl is so permissive, there is much room for error. This chapter shows many techniques for finding errors, including the use of the Perl debugger itself.

Unix vs. Windows

Perl programs run in many environments, though the two major operating systems in the marketplace of 2002 are Unix and Windows (and their variants). As you will see, there is a slight difference between executing a Perl program in these two environments. To normalize the way a Perl program is executed in this book, we will always use the % symbol as the system prompt. If you are using Unix, the first line of every script needs to be:


where the first two characters are #! and the rest of the line is the complete pathname for the Perl executable. We used /usr/bin/perl, where it is located on Linux, but it may be different on your system.

We will simply give the name of a Perl program to execute it, although on Windows, you'll need to put the word "perl" in front of the executable file. On Unix, you will want to make each file executable by using the chmod command. We will not show the chmod command being executed each time. We will simply show the execution of Perl scripts as follows:

% countfiles.plThere are 10 files in the current directory%

Filenames for Perl scripts

In the Perl world, there is no restriction on the naming of Perl executable files. Despite this lack of restriction, we will always name our example scripts with the .pl extension.

Standard input and standard output redirections

Perl matured on Unix. On those systems, there is a common notion of two popular files-the standard input file (the keyboard) and the standard output file (the display). This nomenclature has been adopted by the Windows world as well. Thus, we will often speak of a program that reads from the standard input, and we will also speak of a program that writes to the standard output. The following program is one of them:

% addinput.plEnter first number 25Enter second number 50Sum is 75%

The < symbol may be used to redirect the standard input so that the data can come from a disk file. The > symbol may be used to redirect the standard output to a disk file. We will use these notations whenever necessary. For example, the following demonstrates how to read from a disk file and write to another disk file:

% printlines.pl < inputfile > outputfile

Because of the < symbol, the program takes its input from the file named inputfile rather than from the keyboard. Likewise, the program directs its output to the disk file named outputfile rather than to the display.

The newline character

If you are a Unix user, you are familiar with the newline character. It is generated when the user presses the Return (or Enter) key. Perl scripts honor this convention regardless of the operating system.

Writing style

In writing a book about a programming language, the author is faced with many different decisions. Since this book contains many complete code examples, I must show you the code and explain it. This leads to two inevitable choices: show the code and then write about it, or write about it and then show the code. There are drawbacks and advantages to each choice. For the most part, I have given the code first and then given the explanation. When you become frustrated reading some of the code, have a little patience, for the explanation will surely follow.

Displaying files

Occasionally, you may need to display a few data files so you can interpret the results of programs. On Unix systems, this is usually accomplished with the cat command; on Windows, this is usually accomplished with the type command. To stay neutral, we will use a mythical display command as follows:

% display datafileMichael   Saltzman   Columbia             MarylandSusan     Saltzman   Charleston           South CarolinaErin      Flanagan   Annapolis            MarylandPatti     Ordonez    Columbia             MarylandMaria     Gonzalez   Pikesville           MarylandDave      Flanagan   Bowie                MarylandBob       Knox       Ft. Lauderdale       Florida%

Source files

All of the code that comprises the examples in this book may be found online and can be downloaded. In addition, each chapter has some exercises that support the topics in the chapters. These solutions can also be found online at http://www.phptr.com/saltzman/


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020