Ebook banner rotater for Web Programming and Administration

Perl 5

by Example

by David Medinets


C  O  N  T  E  N  T  S




Chapter 1   Getting Your Feet Wet

Chapter 2   Numeric and String Literals

Chapter 3   Variables

Chapter 4   Operators

Chapter 5   Functions

Chapter 6   Statements

Chapter 7   Control Statements

Chapter 8   References

Chapter 9   Using Files

Chapter 10   Regular Expressions

Chapter 11   Creating Reports

Chapter 12   Using Special Variables

Chapter 13   Handling Errors and Signals

Chapter 14   What Are Objects?

Chapter 15   Perl Modules

Chapter 16   Debugging Perl

Chapter 17   Using Command-Line Options

Chapter 18   Using Internet Protocols

Chapter 19   What Is CGI?

Chapter 20   Form Processing

Chapter 21   Using Perl with Web Servers

Chapter 22   Internet Resources

Appendix A   Answers to Review Questions

Appendix B   Glossary

Appendix C   Function List

Appendix D   Using the Registry


Credits


Copyright© 1996 by Que Corporation.

All rights reserved. Printed in the United States of America. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 W. 103rd Street, Indianapolis, IN 46290. You may reach Que's direct sales line by calling 1-800-428-5331.

ISBN: 0-7897-0866-3
HTML conversion by :
    M/s. LeafWriters (India) Pvt. Ltd.
    Website : http://leaf.stpn.soft.net
    e-mail : leafwriters@leaf.stpn.soft.net


PresidentRoland Elgey
PublisherJoseph B. Wikert
Director of Marketing Lynn E. Zingraf

Editorial Services Director Elizabeth Keaffaber Managing Editor Sandy Doell
Title Manager Bryan GambrelProject Director Al Valvano
Production Editors Susan Ross Moore, Matthew B. Cox EditorsElizabeth Barrett, Anne Owen, Jeff Riley
Product Marketing Manager Kim Margolius Assistant Product Marketing Manager Christy M. Miller
Technical Editors Joe Milton, J. David Shinn, CNE, Synergetic Resource Corp. Technical Specialist Nadeem Muhammed
Acquisitions Coordinator Carmen Krikorian Operations Coordinator Patricia J. Brooks
Editorial Assistant Andrea Duvall Book DesignerBarb Kordesh
Cover Designer Ruth HarveyProduction Bryan Flores


About the Author

David Medinets has been programming since 1980, when he started with a TRS-80 Model 1. He still fondly remembers the days when he could crosswire the keyboard to create funny-looking characters on the display. Since those days, he has spent time debugging Emacs on UNIX machines, working on VAXen, and messing around with DOS microcomputers. David is married to Kathryn and lives in northwest New Jersey. He runs Eclectic Consulting and has coauthored Special Edition Using Lotus Notes Release 4 (Que), Special Edition Using Turbo C++ 4.5 for Windows (Que), Microsoft Office 95 Unleashed (Sams), and Visual Basic Unleashed (Sams), among others. David can be reached at medined@planet.net.

Acknowledgments

I'd like to thank all of the people at Que for making this book possible. You'll find their names listed on the Credits page, so I won't list them all here. Susan Ross Moore deserves special thanks for figuratively watching over my shoulder as I worked. Her comments definitely made this a better book. Al Valvano was instrumental in making sure that everything came together at the proper time.

My wonderful wife deserves some thanks for letting me hang out on the Internet at all hours of the day and night while I did research for this book.

While writing this book, I have gleaned information from many books, articles, and Web resources. Where a particular item greatly influenced my thinking, I have given credit in the appropriate section.

Dale Bewley helped to create Chapter 19, "What Is CGI?"-Thanks Dale!

And of course, no Perl author should forget to thank: Larry Wall for creating Perl in the first place; Tom Christiansen for his remarkable contributions to the Perl community; and Randal Schwartz for his Learning Perl book which every Perl programmer seems to have read.

Thanks,
David

We'd Like to Hear from You!

As part of our continuing effort to produce books of the highest possible quality, Que would like to hear your comments. To stay competitive, we really want you, as a computer book reader and user, to let us know what you like or dislike most about this book or other Que products.

You can mail comments, ideas, or suggestions for improving future editions to the address below, or send us a fax at (317) 581-4663. Our staff and authors are available for questions and comments through our Internet site, at http://www.mcp.com/que, and Macmillan Computer Publishing also has a forum on CompuServe (type GO QUEBOOKS at any prompt).

In addition to exploring our forum, please feel free to contact me personally to discuss your opinions of this book: I'm avalvano@que.mcp.com on the Internet, and 74671,3710 on CompuServe.

Thanks in advance-your comments will help us to continue publishing the best books available on new computer technologies in today's market.

Al Valvano
Project Director
Que Corporation
201 W. 103rd Street
Indianapolis, Indiana 46290
USA

Introduction

This book is based on the learn-by-doing principle because I believe that simply reading about a subject makes it harder to learn. After all, you don't read about putting together a jigsaw puzzle; you put the puzzle together yourself! Programming is the same way. You must actually run some programs in order to really understand the concepts.

Perl 5 By Example will teach you how to use the Perl programming language by showing examples that demonstrate the concepts being discussed. The examples are designed to give you a chance to experiment-which in turn should clarify the material.

Additional information and errata pages can be found at http://www.mtolive. com/pbe/index.html.

The topics are covered in a straightforward, nontechnical manner, which allows you to quickly understand the fundamental principles. After the main topic of each chapter is introduced, subtopics are explored in their own sections. Each section has its own Perl examples with explanations given in pseudocode.

Each chapter finishes with review questions of varying difficulty based on the material in that chapter. The answers usually come from the text or are deducible from the text, but occasionally you might need to experiment a little. Try to answer the questions at all difficulty levels. If you get stuck turn to the answers provided in Appendix A. Also, look at the summary sections after reading each chapter and return to them frequently. After you've gone through several chapters, you'll begin to understand more often the reason why a concept was illustrated or a question was asked. Returning to questions that frustrated you earlier and realizing that now you know the answers can be a big confidence builder.

Who Should Use This Book?

Perl 5 By Example should be read by anyone seeking to learn Perl. If you don't know any other programming languages, Chapters 2 through 7 will give you a solid introduction to the basics. If you already know another language, then skip Chapters 2 through 7 to see how Perl differs from other languages and start with Chapter 8, "References."

This book follows a simple format. Each chapter contains a single topic-usually. First, you read about the topic and then you see examples that let you work directly with Perl to understand how the concepts can be applied to a program. At the end of each chapter is a summary, followed by review questions and exercises.

This approach is designed to serve a broad range of readers from novice to advanced. If you've never programmed before, the learn-by-doing approach will help you move quickly and easily though this book. If you have programming experience, you'll find plenty of material to refine and enhance what you already know, and to give you a solid understanding of how Perl works.

What Do I Need?

In order to effectively use this book you need two things. You need a working copy of Perl 5. And you need a text editor. That's it.

You can use the examples in this book with just about any hardware and operating system. I'm not sure that they would work on an Amiga system but other than that you should be able to run every example.

How to Use This Book

There are several ways to use this book. One obvious method is to begin at the first page and proceed in order until t