To my family, my wife Madeline for giving me the time and encouragement, and my children Delenn, Duncan, and Diego for setting my life in perspective. -BB
Copyright © 1996 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams Publishing, 201 W. 103rd St., Indianapolis, IN 46290.
International Standard Book Number: 0-672-30891-6
HTML conversion by :
M/s. LeafWriters (India) Pvt. Ltd.
Website : http://leaf.stpn.soft.net
e-mail : firstname.lastname@example.org
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
|Publisher||Richard K. Swadley|
|Publishing Team Leader||Greg Wiegand|
|Managing Editor||Cindy Morrow|
|Director of Marketing||John Pierce|
|Assistant Marketing Managers||Kristina Perry, Rachel Wolfe|
|Acquisitions Editor||Christopher Denny||Development Editor||Anthony Amico|
|Software Development Specialist||Brad Myers||Production Editors||Kristi Hart, Katherine Ewing|
|Copy Editor||Bart Reed||Indexer||Chris Barrick|
|Technical Reviewers||Zachary Bir, John Fleming, Elliotte Harold, Scott Hutton, Matt Liggett, John Neinart||Editorial Coordinator||Bill Whitmer|
|Technical Edit Coordinator||Lynette Quinn||Editorial Assistants||Carol Ackerman, Andi Richter, Rhonda Tinch-Mize|
|Cover Designer||Tim Amrhein||Book Designer||Gary Adair|
|Copy Writer||Peter Fuller||Production Team Supervisor||Brad Chinn|
|Production||Debra Bolhuis, Mona Brown, Michael Dietsch, Jason Hand, Daniel Harris, Bill Hartman, Susan Knose, Clint Lahnen, Paula Lowell, Laura Robbins, Bobbi Satterfield, Susan Van Ness, Suzanne Whitmer|
First of all, I would like to thank Chris Denny at Sams for giving me the opportunity to write a book on Perl 5. I would also to thank Kristi Hart, Tony Amico, and Bart Reed for their patience, help, advice, and forcing me to keep up with deadlines.
I'd like to thank Uzma, my wife, and Haya and Hana, my twin daughters, for putting up with my weird schedules and odd hours.
Last, but definitely not the least, thanks to all the Perl programmers on Perl mailing lists for all the critique and comments via e-mail.
Robert F. Breedlove is a senior systems engineer with EDS. He has over 20 years of experience in data processing including extensive client/server, UNIX, intranet and Internet experience. He can be reached at email@example.com, or at his homepage: http://www.channel1.com/users/rbreed01/.
As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make strong books that meet your needs and give you the computer guidance you require.
Do you have access to CompuServe or the World Wide Web? Then check out our CompuServe forum by typing GO SAMS at any prompt. If you prefer the World Wide Web, check out our site at http://www.mcp.com.
If you have a technical question about this book, call the technical support line at (800) 571-5840, ext. 3668.
As the team leader of the group that created this book, I welcome
your comments. You can fax, e-mail, or write me directly to let
me know what you did or didn't like about this book-as well as
what we can do to make our books stronger. Here's the information:
201 W. 103rd Street
Indianapolis, IN 46290
This book documents a very powerful language called Perl 5, which is version 5 of Larry Wall's creation, Perl. Perl is fast becoming the de facto language for UNIX system administrators, Webmasters on the World Wide Web, and programmers who want a fast, powerful, and easy-to-use program language. This book will provide you with the basics of the language and introduce you to the tools available for Perl.
While writing this book, I assumed that you, the reader, have had some prior programming experience. If you do not have any prior programming experience, I strongly suggest not skipping the first three chapters. If you are already a programmer and are familiar with Perl 4, this book should provide you with enough knowledge to use the great new features.
This book is divided into six parts.
The first part provides a brief introduction to Perl as a programming language. It covers the use of references to variables, regular expressions, and the fundamentals of programming in Perl by using modules. It introduces the use of Perl for programming with an object-oriented paradigm. It also covers the not-so-basic but very important topic of tying variables in Perl programs.
The second part covers applying Perl to different platforms and types of applications. It begins with a chapter on processing patterns and strings in Perl. For a long time, I debated reversing the order of Chapters 6 and 7 because the concepts are both fundamental, but the chapter on tying variables seemed to fit in the first part. Most of the portability issues in programming in Perl on a Windows platform are also discussed in this part.
The third part gets into networking and system-level programming issues for Perl. The basic communications features in Perl include sockets, System V Ipc messaging facilities, signals, pipes, and FIFOs, and are covered in this part. The basics of handling the command-line interface as well as a graphical user interface using Tcl/Tk and Perl are also covered in this part. The last two chapters of this part introduce the use of database front-ends and the report-generating facilities of Perl. The information in this part serves as the basis for writing Perl applications that can provide reports on data stored in databases.
Section four introduces the World Wide Web and the Common Gateway Interface (CGI). Thick books have been written on these topics, and this part attempts to present the most practical information required to get you started writing CGI scripts and your own Web pages. This part covers how to access databases from within Perl and how to write your own module to generate VRML objects. The information in this chapter can serve as a basis for writing your own CGI scripts using the modules available on the World Wide Web for Perl.
The chapters in this part are geared towards the advanced user or the system administrator who has to install Perl on various platforms. The topics in this part tend to be centered on UNIX systems, but that's just where most of the heavy Perl development seems to be. I cover the internal data types used in Perl, and then based on this knowledge I go on to show the techniques of writing extensions and embedding Perl in C programs.
This part covers the use of the Perl debugger. This was the part where I wanted to present some case studies on how to use Perl as a prototyping language to solve problems. I use Perl to solve some real-world problems involving parsing weird data formats and creating images on demand, and then I discuss issues on how to debug CGI applications. This part also covers how to use Java applets on a client to communicate with Perl servers, which is a hot Internet topic.
The following typographic conventions are used in this book:
Now for a personal disclaimer of sorts. Even though I attempt to cover all the major points of the latest release of Perl, version 5.002 at the time we go to print, I probably will never be able to list all the features of this wonderful language. If there is one thing that I've learned while working with Perl, it is that there are so many ways of doing any one task. Every time I write a Perl script, I think that I "could've done it this way and maybe it'll run faster." The number of combinations of things to do with Perl never really ends. So, if you find a better way of writing Perl scripts than the ones shown in this book, don't be surprised-it's bound to happen. Do drop me a line, though, because I will incorporate them into the next edition of this book. I look forward to receiving all your comments and, yes, even criticisms and the usual flames.