Statistics
18
Views
0
Downloads
0
Donations
Uploader

高宏飞

Shared on 2025-12-21
Support
Share

AuthorRandal L. Schwartz, brian d foy, Tom Phoenix

<p>If you're just getting started with Perl, this is the book you want—whether you're a programmer, system administrator, or web hacker. Nicknamed "the Llama" by two generations of users, this best seller closely follows the popular introductory Perl course taught by the authors since 1991. This eighth edition covers recent changes to the language up to version 5.34.</p><p>Perl is suitable for almost any task on almost any platform, from short fixes to complete web applications. Learning Perl teaches you the basics and shows you how to write simple, single-file programs—roughly 90% of the Perl programs in use today. And each chapter includes exercises to help you practice what you've just learned. Other books may teach you to program in Perl, but this book will turn you into a Perl programmer.</p><p>Topics include:</p><ul><li>Perl data and variable types</li><li>Subroutines</li><li>File operations</li><li>Regular expressions</li><li>String manipulation (including Unicode)</li><li>Lists and sorting</li><li>Process management</li><li>Use of third-party modules</li></ul>

Tags
No tags
ISBN: 1492094951
Publisher: O'Reilly Media
Publish Year: 2021
Language: 英文
Pages: 398
File Format: PDF
File Size: 5.5 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Randal L. Schwartz, brian d foy & Tom Phoenix 8th Edition Covers Perl 5.34Learning Perl Making Easy Things Easy and Hard Things Possible
(This page has no text content)
Praise for Learning Perl Still the best way to learn Perl: friendly, accurate, and encouraging. —Nathan Torkington, Coauthor of the Perl Cookbook I consider the Llama the de facto standard when it comes to an introductory book for the Perl language. It’s coherent, easy to approach, and it broadly covers the language from legacy information to the bleeding edge. —Grzegorz Szpetkowski, Software Engineer, Intel Technology Poland Learning Perl is an investment that will help unlock the full potential of this powerful programming language. The authors are insightful as they methodically tackle a maze of new and exciting concepts that should be part of everyone’s journey towards Perl proficiency. —André Philipp, Freelance software engineer Learning Perl [4th ed.] should rightly be regarded as one of the classic texts for Perl programmers to read through at least once in their Perl careers. The book is chock-full of useful information, and even experienced Perl coders would do well to at least leaf through the pages of this book for paradigms to help their coding. —Craig Maloney, Slashdot reviewer
(This page has no text content)
Randal L. Schwartz, brian d foy, and Tom Phoenix Learning Perl Making Easy Things Easy and Hard Things Possible EIGHTH EDITION Boston Farnham Sebastopol TokyoBeijing
978-1-492-09495-1 [GP] Learning Perl by Randal L. Schwartz, brian d foy, and Tom Phoenix Copyright © 2021 Enhydra Services, LLC. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Suzanne McQuade Development Editor: Jill Leonard Production Editor: Daniel Elfanbaum Copyeditor: Audrey Doyle Proofreader: Kim Cofer Indexer: WordCo Indexing Services, Inc. Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea July 2021: Eighth Edition Revision History for the Eighth Edition 2021-06-29: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781492094951 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning Perl, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors, and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii 1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Questions and Answers 1 Is This the Right Book for You? 1 What About the Exercises and Their Answers? 2 What If I’m a Perl Course Instructor? 3 What Does “Perl” Stand For? 4 Why Did Larry Create Perl? 4 Why Didn’t Larry Just Use Some Other Language? 4 Is Perl Easy or Hard? 5 How Did Perl Get to Be So Popular? 6 What’s Happening with Perl Now? 7 What’s Perl Really Good For? 7 What Is Perl Not Good For? 8 How Can I Get Perl? 8 What Is CPAN? 9 Is There Any Kind of Support? 9 What If I Find a Bug in Perl? 10 How Do I Make a Perl Program? 10 A Simple Program 11 What’s Inside That Program? 13 How Do I Compile My Perl Program? 15 A Whirlwind Tour of Perl 15 Exercises 17 v
2. Scalar Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Numbers 19 All Numbers Have the Same Format Internally 20 Integer Literals 20 Nondecimal Integer Literals 20 Floating-Point Literals 21 Numeric Operators 22 Strings 23 Single-Quoted String Literals 23 Double-Quoted String Literals 24 String Operators 25 Automatic Conversion Between Numbers and Strings 26 Perl’s Built-in Warnings 27 Interpreting Nondecimal Numerals 28 Scalar Variables 29 Choosing Good Variable Names 30 Scalar Assignment 31 Compound Assignment Operators 31 Output with print 32 Interpolation of Scalar Variables into Strings 32 Creating Characters by Code Point 34 Operator Precedence and Associativity 34 Comparison Operators 36 The if Control Structure 37 Boolean Values 37 Getting User Input 38 The chomp Operator 39 The while Control Structure 40 The undef Value 40 The defined Function 41 Exercises 42 3. Lists and Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Accessing Elements of an Array 44 Special Array Indices 45 List Literals 45 The qw Shortcut 46 List Assignment 47 The pop and push Operators 49 The shift and unshift Operators 49 The splice Operator 50 vi | Table of Contents
Interpolating Arrays into Strings 51 The foreach Control Structure 52 Perl’s Favorite Default: $_ 53 The reverse Operator 53 The sort Operator 54 The each Operator 54 Scalar and List Context 55 Using List-Producing Expressions in Scalar Context 56 Using Scalar-Producing Expressions in List Context 57 Forcing Scalar Context 58 <STDIN> in List Context 58 Exercises 59 4. Subroutines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Defining a Subroutine 61 Invoking a Subroutine 62 Return Values 62 Arguments 64 Private Variables in Subroutines 66 Variable-Length Parameter Lists 67 A Better &max Routine 67 Empty Parameter Lists 68 Notes on Lexical (my) Variables 69 The use strict Pragma 70 The return Operator 71 Omitting the Ampersand 72 Nonscalar Return Values 74 Persistent, Private Variables 74 Subroutine Signatures 76 Prototypes 78 Exercises 79 5. Input and Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Input from Standard Input 81 Input from the Diamond Operator 83 The Double Diamond 85 The Invocation Arguments 85 Output to Standard Output 86 Formatted Output with printf 89 Arrays and printf 91 Filehandles 91 Table of Contents | vii
Opening a Filehandle 93 Binmoding Filehandles 96 Bad Filehandles 96 Closing a Filehandle 97 Fatal Errors with die 97 Warning Messages with warn 99 Automatically die-ing 99 Using Filehandles 100 Changing the Default Output Filehandle 100 Reopening a Standard Filehandle 101 Output with say 101 Filehandles in a Scalar 102 Exercises 104 6. Hashes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 What Is a Hash? 105 Why Use a Hash? 107 Hash Element Access 108 The Hash as a Whole 109 Hash Assignment 110 The Big Arrow 111 Hash Functions 112 The keys and values Functions 112 The each Function 113 Typical Use of a Hash 115 The exists Function 115 The delete Function 115 Hash Element Interpolation 116 The %ENV Hash 116 Exercises 117 7. Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Sequences 119 Practice Some Patterns 121 The Wildcard 123 Quantifiers 125 Grouping in Patterns 129 Alternation 132 Character Classes 134 Character Class Shortcuts 135 Negating the Shortcuts 136 viii | Table of Contents
Unicode Properties 136 Anchors 137 Word Anchors 139 Exercises 140 8. Matching with Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Matches with m// 141 Match Modifiers 142 Case-Insensitive Matching with /i 142 Matching Any Character with /s 142 Adding Whitespace with /x 143 Combining Option Modifiers 145 Choosing a Character Interpretation 145 Beginning- and End-of-Line Anchors 147 Other Options 148 The Binding Operator =~ 148 The Match Variables 149 The Persistence of Captures 150 Captures in Alternations 151 Noncapturing Parentheses 153 Named Captures 154 The Automatic Match Variables 156 Precedence 158 Examples of Precedence 159 And There’s More 159 A Pattern Test Program 160 Exercises 160 9. Processing Text with Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Substitutions with s/// 163 Global Replacements with /g 164 Different Delimiters 165 Substitution Modifiers 165 The Binding Operator 165 Nondestructive Substitutions 165 Case Shifting 166 Metaquoting 168 The split Operator 168 The join Function 170 m// in List Context 170 More Powerful Regular Expressions 171 Table of Contents | ix
Nongreedy Quantifiers 171 Fancier Word Boundaries 173 Matching Multiple-Line Text 174 Updating Many Files 174 In-Place Editing from the Command Line 177 Exercises 178 10. More Control Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 The unless Control Structure 179 The else Clause with unless 180 The until Control Structure 180 Statement Modifiers 181 The Naked Block Control Structure 182 The elsif Clause 183 Autoincrement and Autodecrement 184 The Value of Autoincrement 184 The for Control Structure 185 The Secret Connection Between foreach and for 187 Loop Controls 188 The last Operator 188 The next Operator 189 The redo Operator 190 Labeled Blocks 191 The Conditional Operator 192 Logical Operators 193 The Value of a Short-Circuit Operator 194 The defined-or Operator 195 Control Structures Using Partial-Evaluation Operators 196 Exercises 198 11. Perl Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Finding Modules 199 Installing Modules 200 Using Your Own Directories 201 Using Simple Modules 203 The File::Basename Module 204 Using Only Some Functions from a Module 205 The File::Spec Module 206 Path::Class 207 Databases and DBI 208 Dates and Times 209 x | Table of Contents
Exercises 210 12. File Tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 File Test Operators 211 Testing Several Attributes of the Same File 215 Stacked File Test Operators 217 The stat and lstat Functions 218 The localtime Function 219 Bitwise Operators 220 Using Bitstrings 221 Exercises 224 13. Directory Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 The Current Working Directory 225 Changing the Directory 226 Globbing 227 An Alternate Syntax for Globbing 229 Directory Handles 230 Manipulating Files and Directories 232 Removing Files 232 Renaming Files 233 Links and Files 235 Making and Removing Directories 239 Modifying Permissions 241 Changing Ownership 241 Changing Timestamps 242 Exercises 242 14. Strings and Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Finding a Substring with index 245 Manipulating a Substring with substr 247 Formatting Data with sprintf 248 Using sprintf with “Money Numbers” 249 Advanced Sorting 250 Sorting a Hash by Value 254 Sorting by Multiple Keys 255 Exercises 256 15. Process Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 The system Function 257 Avoiding the Shell 260 Table of Contents | xi
The Environment Variables 262 The exec Function 263 Using Backquotes to Capture Output 264 Using Backquotes in a List Context 267 External Processes with IPC::System::Simple 268 Processes as Filehandles 269 Getting Down and Dirty with fork 271 Sending and Receiving Signals 272 Exercises 275 16. Some Advanced Perl Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Slices 277 Array Slice 279 Hash Slice 281 Key-Value Slices 282 Trapping Errors 283 Using eval 283 More Advanced Error Handling 287 Picking Items from a List with grep 289 Transforming Items from a List with map 290 Fancier List Utilities 291 Exercises 293 A. Exercise Answers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 B. Beyond the Llama. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 C. A Unicode Primer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 D. Experimental Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 xii | Table of Contents
Preface Welcome to the eighth edition of Learning Perl, updated for Perl 5.34 and its latest features. This book is still mostly good even if you are still using Perl 5.8 (although, it’s been a long time since it was released; have you thought about upgrading?). If you’re looking for the best way to spend your first 30 to 45 hours with the Perl pro‐ gramming language, you’ve found it. In the pages that follow, you’ll find a carefully paced introduction to the language that is the workhorse of the internet, as well as the language of choice for system administrators, web hackers, and casual programmers around the world. We’ve designed this book based on the in-person classes we teach, so we’ve timed the book for a week’s worth of work. We hope you’re reading this preface before you buy the book, because there’s a histor‐ ical hiccup that may cause some confusion. There’s another language, Perl 6, that started off as a replacement for Perl 5 but then went out on its own with the new name “Raku” (although brian’s book on that language is still Learning Perl 6). Along with that, there’s currently a move to make a new major version of Perl, Perl 7. That’s supposed to be Perl v5.34 with different defaults as a baby step to evolving the language. Since it’s basically Perl 5, it should be able to run Perl 5 programs, although perhaps with a compatibility switch. As we write this, we’re not sure how that will shake out. After you finish this book, you may like to read another book by brian, Preparing for Perl 7. Since much of that advice is simply modern good practices, we’ll try to give you that same advice in this book. As we write this, Perl 5 is probably the version you want. It’s the widely installed and used language that people mean when they say simply “Perl.” It’s going to be the inter‐ esting and most used version for a long time. It’s the one you want if you don’t know why this paragraph is here. We can’t give you all of Perl in just a few hours. The books that promise to do that are probably fibbing a bit. Instead, we’ve carefully selected a useful subset of Perl for you to learn, good for programs from 1 to 128 lines long (an arbitrary number), which xiii
end up being about 90% of the programs in use out there. And when you’re ready to go on, you can get Intermediate Perl, which picks up where this book leaves off. We’ve also included a number of pointers for further education. Each chapter is short enough for you to read in an hour or two. Each chapter ends with a series of exercises to help you practice what you’ve just learned, with the answers in Appendix A for your reference. Thus, this book is ideally suited for a classroom “Introduction to Perl” course. We know this directly because the material for this book was lifted almost word for word from our flagship “Learning Perl” course, delivered to thousands of students around the world. However, we’ve designed the book for self-study as well. brian provides additional exercises and detailed answers in a separate companion book, Learning Perl Exercises. Perl lives as the “toolbox for Unix,” but you don’t have to be a Unix guru, or even a Unix user, to read this book. Unless otherwise noted, everything we’re saying applies equally well to Windows ActivePerl from ActiveState and Strawberry Perl and pretty much every other modern implementation of Perl. Although you don’t need to know a single thing about Perl to begin reading this book, we recommend that you already have familiarity with basic programming concepts such as variables, loops, subroutines, and arrays, and the all-important “editing a source code file with your favorite text editor.” We don’t spend any time trying to explain those concepts. Although we’re pleased that we’ve had many reports of people successfully picking up Learning Perl and grasping Perl as their first programming language, of course we can’t promise the same results for everyone. Typographical Conventions The following font conventions are used in this book: Constant width Used for method names, function names, variables, and attributes. It is also used for code examples. Constant width bold Used to indicate user input. Constant width italic Used to indicate a replaceable item in code (e.g., filename, where you are sup‐ posed to substitute an actual filename). xiv | Preface
Italic Used for filenames, URLs, hostnames, commands in text, important words on first mention, and emphasis. [37] At the start of an exercise’s text, we provide a (very rough) estimate of how many minutes you can expect to spend on that particular exercise. Code Examples This book is here to help you get your job done. You are invited to copy the code in the book and adapt it for your own needs. Rather than copying by hand, however, we encourage you to download the code from the book’s companion website. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require per‐ mission. We appreciate, but do not require, attribution. An attribution usually includes the title, authors, publisher, and ISBN. For example: “Learning Perl, 8th edition, by Ran‐ dal L. Schwartz, brian d foy, and Tom Phoenix (O’Reilly). Copyright 2021 Enhydra Services, LLC, 978-1-492-09495-1.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permis‐ sions@oreilly.com. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit http://oreilly.com. Preface | xv
1 In the contract, I retained the rights to the exercises, hoping someday to reuse them in some other way, like in the magazine columns I was writing at the time. The exercises are the only things that leapt from the Taos course to the book. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/learning-perl-8e. Email bookquestions@oreilly.com to comment on or ask technical questions about this book. For news and information about our books and courses, visit http://oreilly.com. Find us on Facebook: http://facebook.com/oreilly. Follow us on Twitter: http://twitter.com/oreillymedia. Watch us on YouTube: http://www.youtube.com/oreillymedia. History of This Book For the curious, here’s how Randal tells the story of how this book came about: After I had finished the first Programming perl book with Larry Wall (in 1991), I was approached by Taos Mountain Software in Silicon Valley to produce a training course. This included having me deliver the first dozen or so courses and train their staff to continue offering the course. I wrote the course for them1 and delivered it for them as promised. On the third or fourth delivery of that course (in late 1991), someone came up to me and said, “You know, I really like Programming perl, but the way the material is pre‐ sented in this course is so much easier to follow—you oughta write a book like this course.” It sounded like an opportunity to me, so I started thinking about it. xvi | Preface
2 My Taos contract had a noncompete clause, so I had to stay out of Silicon Valley with any similar courses, which I respected for many years. 3 I remember that date very well, because it was also the day I was arrested at my home for computer-related activities around my Intel contract, a series of felony charges for which I was later convicted. I wrote to Tim O’Reilly with a proposal based on an outline that was similar to the course I was presenting for Taos—although I had rearranged and modified a few of the chapters based on observations in the classroom. I think that was my fastest pro‐ posal acceptance in history—I got a message from Tim within 15 minutes, saying “We’ve been waiting for you to pitch a second book—Programming perl is selling like gangbusters.” That started the effort over the next 18 months to finish the first edition of Learning Perl. During that time, I was starting to see an opportunity to teach Perl classes outside Silicon Valley,2 so I created a class based on the text I was writing for Learning Perl. I gave a dozen classes for various clients (including my primary contractor, Intel Ore‐ gon), and used the feedback to fine-tune the book draft even further. The first edition hit the streets on the first day of November 1993,3 and became a smashing success, frequently even outpacing Programming perl book sales. The back-cover jacket of the first book said “written by a leading Perl trainer.” Well, that became a self-fulfilling prophecy. Within a few months, I was starting to get email from all over the United States asking me to teach at their site. In the following seven years, my company became the leading worldwide on-site Perl training com‐ pany, and I had personally racked up (literally) a million frequent-flier miles. It didn’t hurt that the web started taking off about then, and the webmasters and webmis‐ tresses picked Perl as the language of choice for content management, interaction through CGI, and maintenance. For two years, I worked closely with Tom Phoenix in his role as lead trainer and con‐ tent manager for Stonehenge, giving him charter to experiment with the “Llama” course by moving things around and breaking things up. When we had come up with what we thought was the best major revision of the course, I contacted O’Reilly and said, “It’s time for a new book!” And that became the third edition. Two years after writing the third edition of the Llama, Tom and I decided it was time to push our follow-on “advanced” course out into the world as a book, for people writing programs that are “100 to 10,000 lines of code.” And together we created the first Alpaca book (Learning Perl Objects, References, and Modules), released in 2003. But fellow instructor brian d foy had noticed that we could use some rewriting in both books, because our courseware still needed to track the changing needs of the typical student. So, he pitched the idea to O’Reilly to take on rewriting both the Llama and the Alpaca. This edition of the Llama reflects those changes. brian has really been Preface | xvii
the lead writer here, working with my occasional guidance, and has done a brilliant job of the usual “herding cats“ that a multiple-writer team generally feels like. On December 18, 2007, the Perl 5 Porters released Perl 5.10, a significant new version of Perl with several new features. The previous version, 5.8, had focused on the underpinnings of Perl and its Unicode support. The latest version, starting from the stable 5.8 foundation, was able to add completely new features, some of which it bor‐ rowed from the development of Perl 6. Some of these features, such as named cap‐ tures in regular expressions, are much better than the old ways of doing things, thus perfect for Perl beginners. We hadn’t thought about a fifth edition of this book, but Perl 5.10 was so much better that we couldn’t resist. Since then, Perl has been under constant improvement and is keeping a regular release cycle. Each new Perl release has brought exciting new features, many of which programmers have wanted for years. As long as Perl keeps doing that, we’ll keep updating this book. Changes from the Previous Edition The text is updated for the latest version, Perl 5.34, and some of the code only works with that version. We note in the text when we are writing about a Perl 5.34 feature, and we mark those code sections with a special use statement that ensures you’re using the right version: use v5.34; # this script requires Perl 5.34 or greater If you don’t see that use v5.34 in a code example (or a similar statement with a dif‐ ferent version), it should work all the way back to Perl 5.8. To see which version of Perl you have, try the -v command-line switch: $ perl -v In some examples, we’ll show a lower minimum Perl version because that’s all the program needs. For instance, say was introduced in Perl v5.10: use v5.10; say "Howdy, Fred!"; In most cases, we’ll probably forgo a new feature to make the examples work on as many versions of Perl as possible. That doesn’t mean you shouldn’t use the new fea‐ tures or that we don’t endorse them. We simply have a wide audience for this book. We include Unicode examples and features where appropriate. If you haven’t started playing with Unicode, you may want to read our primer in Appendix C. You have to bite the bullet sometimes, so it might as well be now. You’ll see Unicode throughout the book, most notably in the chapters on scalars (Chapter 2), input/output (Chapter 5), and sorting (Chapter 14). xviii | Preface
The above is a preview of the first 20 pages. Register to read the complete e-book.