This book made available by the Internet Archive.
preface
The Norse God Odin had two ravens, Hugin and Munin (Thought and Memory). He would send them out each day to fly to the corners of the earth. At night, they would return and tell him all their secrets. Odin knew how to manage his resources. Thought and memory, cogitation and recall, processing and storageas a programmer, these are the important resources you too must tame. This book aims to be your guide in this endeavor. By the time you finish this book, you should have the skills to manage your own Hugin and Munin. In other words, you will be able to write your own hugin Perl program to scour the web for interesting information, as well as a munin program to manage and query the database of information you collect.
There are a lot of books about Perl on the market today, and some of them I recommend highly. (See Appendix C, "Additional resources.") However, many authors of these other Perl books assume readers are already familiar with programming. Other authors take the side-effect approach, teaching readers the vocabulary and syntax of the language but offering few guidelines on how to use it effectively. I do not believe that the side-effect approach is an effective means of teaching programming.
This book instead presents the basic elements of programming using the context of the Perl language. I do not assume that you've programmed before, nor do I merely hammer you with syntax and function names. This book is designed to teach you both programming and Perl, from the basics to the more advanced skills you need to become an accomplished Perl programmer.
Audience
This book is intended for two types of readers: those approaching Perl as their first programming language and those who may have learned programming off the cuff
but now want a more thorough grounding in programming in general, and Perl in particular.
More people than ever are learning Perl. Undoubtedly, Perl's widespread use for Common Gateway Interface (CGI) and web-client programming contributes to its popularity. Some people need Perl skills for their jobs, while others just think Perl programming is cool. Whatever your motivation, you need to understand up front that this book is not about using Perl for web-related programming, although an example or two illustrates that application of Perl. Instead, this book is about learning how to program using Perl. Once you have that knowledge under your belt, you can apply it to a multitude of problem domains.
This book does not assume that you know what variables, arrays, and loops are, or that you've programmed before. However, familiarity with basic mathematical concepts and logic will certainly be helpful. Readers with no prior programming experience should, of course, begin at the beginning and work their way through the first nine chapters in order. Chapters 10 through 15 are largely independent and can be read in any order. Chapters 16 through 19 introduce advanced Perl concepts. Each of these chapters lays a foundation for the following chapter, so read these four chapters in order.
If you are already familiar with elementary Perl programming, you may want to read chapters 2 and 3, and then pick and choose chapters that tackle areas in which you wish to improve. For example, chapters 6, 10, and 11 cover different aspects of regular expressions and matching operators. Chapter 8 covers references.
If you are a competent programmer in another language, this book may still be useful in demonstrating Perl's way of doing things. However, the discussions may not be as concise as you'd like, and the content is not organized as a reference book.
Organization
The book is organized in four main parts, starting with things to consider before you begin programming, followed by the essential aspects of programming with Perl. The third section explores a few of the more practical and Perl-specific areas. Finally, the later chapters introduce more advanced concepts, such as abstract data structures and object oriented-programming using Perl.
Introductory elements The three chapters in this section provide elementary information on programming and the Perl language. Chapters 2 and 3 also delve into the basics of program structure and design. In chapter 3, we work through two examples, providing a whirlwind tour of the Perl language in the process.
xii
PREFACE
Essential elements Chapters 4 through 9 cover the essential concepts and structures you need to learn to program effectively. Here you will find everything from variables to loop control constructs to file input and output to basic regular expressions to subroutines to references and nested data structures. When you finish this section of the book, you will have all the tools you need to build real-world applications. , ; V > . f
Practical elements Chapters 10 through 15 take you into areas more specific to the Perl language, exploiting some of Perl's unique and powerful strengths. Here we explore regular expressions in more detail, string and list processing, more input and output techniques, using modules, and the Perl debugger.
Advanced elements Chapters 16 through 19 provide an introduction to more advanced programming techniques, including building modules and abstract data structures. You are also introduced to object-oriented programming features in Perl. Chapter 20 mentions a few areas not covered in this book and suggests references for fijrther study.
Appendices The four short appendices cover command-line switches, special Perl variables, additional resources for readers, and a brief explanation of binary, octal, and hexadecimal numeric representation. Following the appendices is a small glossary of technical terms used in this book.
Source code, solutionSy and errata
The source code for many of the example programs and modules presented in this book may be obtained from Manning's website. Point your browser to httpill www.manning.com/Johnson for links to the online resources for the book, including source packages.