Learning Perl, 4th Edition By brian d foy, Tom Phoenix, Randal L Schwartz Publisher: O'Reilly Pub Date: July 2005 ISBN: 0-596-10105-8 Pages: 312 Table of Contents | Index Learning Perl, better known as "the Llama book", starts the programmer on the way to mastery Written by three prominent members of the Perl community who each have several years of experience teaching Perl around the world, this latest edition has been updated to account for all the recent changes to the language up to Perl 5.8 Perl is the language for people who want to get work done It started as a tool for UNIX system administrators who needed something powerful for small tasks Since then, Perl has blossomed into a full-featured programming language used for web programming, database manipulation, XML processing, and system administration on practically all platforms while remaining the favorite tool for the small daily tasks it was designed for You might start using Perl because you need it, but you'll continue to use it because you love it Informed by their years of success at teaching Perl as consultants, the authors have reengineered the Llama to better match the pace and scope appropriate for readers getting started with Perl, while retaining the detailed discussion, thorough examples, and eclectic wit for which the Llama is famous The book includes new exercises and solutions so you can practice what you've learned while it's still fresh in your mind Here are just some of the topics covered: data structures minimal matching threading data parsing references objects modules package implementation If you ask Perl programmers today what book they relied on most when they were learning Perl, you'll find that an overwhelming majority will point to the Llama With good reason Other books may teach you to program in Perl, but this book will turn you into a Perl programmer Learning Perl, 4th Edition By brian d foy, Tom Phoenix, Randal L Schwartz Publisher: O'Reilly Pub Date: July 2005 ISBN: 0-596-10105-8 Pages: 312 Table of Contents | Index Copyright Preface History of This Book Typographical Conventions Using Code Examples How to Contact Us Safari Enabled Acknowledgments Chapter 1 Introduction Section 1.1 Questions and Answers Section 1.2 What Does "Perl" Stand For? Section 1.3 How Can I Get Perl? Section 1.4 How Do I Make a Perl Program? Section 1.5 A Whirlwind Tour of Perl Section 1.6 Exercises Chapter 2 Scalar Data Section 2.1 Numbers Section 2.2 Strings Section 2.3 Perl's Built-in Warnings Section 2.4 Scalar Variables Section 2.5 Output with print Section 2.6 The if Control Structure Section 2.7 Getting User Input Section 2.8 The chomp Operator Section 2.9 The while Control Structure Section 2.10 The undef Value Section 2.11 The defined Function Section 2.12 Exercises Chapter 3 Lists and Arrays Section 3.1 Accessing Elements of an Array Section 3.2 Special Array Indices Section 3.3 List Literals Section 3.4 List Assignment Section 3.5 Interpolating Arrays into Strings Section 3.6 The foreach Control Structure Section 3.7 Scalar and List Context Section 3.8 in List Context Section 3.9 Exercises Chapter 4 Subroutines Section 4.1 Defining a Subroutine Section 4.2 Invoking a Subroutine Section 4.3 Return Values Section 4.4 Arguments Section 4.5 Private Variables in Subroutines Section 4.6 Variable-Length Parameter Lists Section 4.7 Notes on Lexical (my) Variables Section 4.8 The use strict Pragma Section 4.9 The return Operator Section 4.10 Non-Scalar Return Values Section 4.11 Exercises Chapter 5 Input and Output Section 5.1 Input from Standard Input Section 5.2 Input from the Diamond Operator Section 5.3 The Invocation Arguments Section 5.4 Output to Standard Output Section 5.5 Formatted Output with printf Section 5.6 Filehandles Section 5.7 Opening a Filehandle Section 5.8 Fatal Errors with die Section 5.9 Using Filehandles Section 5.10 Reopening a Standard Filehandle Section 5.11 Exercises Chapter 6 Hashes Section 6.1 What Is a Hash? Section 6.2 Hash Element Access Section 6.3 Hash Functions Section 6.4 Typical Use of a Hash Section 6.5 Exercises Chapter 7 In the World of Regular Expressions Section 7.1 What Are Regular Expressions? Section 7.2 Using Simple Patterns Section 7.3 Character Classes Section 7.4 Exercises Chapter 8 Matching with Regular Expressions Section 8.1 Matches with m// Section 8.2 Option Modifiers Section 8.3 Anchors Section 8.4 The Binding Operator, =~ Section 8.5 Interpolating into Patterns Section 8.6 The Match Variables Section 8.7 General Quantifiers Section 8.8 Precedence Section 8.9 A Pattern Test Program Section 8.10 Exercises Chapter 9 Processing Text with Regular Expressions Section 9.1 Substitutions with s/// Section 9.2 The split Operator Section 9.3 The join Function Section 9.4 m// in List Context Section 9.5 More Powerful Regular Expressions Section 9.6 Exercises Chapter 10 More Control Structures Section 10.1 The unless Control Structure Section 10.2 The until Control Structure Section 10.3 Expression Modifiers Section 10.4 The Naked Block Control Structure Section 10.5 The elsif Clause Section 10.6 Autoincrement and Autodecrement Section 10.7 The for Control Structure Section 10.8 Loop Controls Section 10.9 Logical Operators Section 10.10 Exercise Chapter 11 File Tests Section 11.1 File Test Operators Section 11.2 The stat and lstat Functions Section 11.3 The localtime Function Section 11.4 Bitwise Operators Section 11.5 Using the Special Underscore Filehandle Section 11.6 Exercises Chapter 12 Directory Operations Section 12.1 Moving Around the Directory Tree Section 12.2 Globbing Section 12.3 An Alternate Syntax for Globbing Section 12.4 Directory Handles Section 12.5 Recursive Directory Listing Section 12.6 Manipulating Files and Directories Section 12.7 Removing Files Section 12.8 Renaming Files Section 12.9 Links and Files Section 12.10 Making and Removing Directories Section 12.11 Modifying Permissions Section 12.12 Changing Ownership Section 12.13 Changing Timestamps Section 12.14 Exercises Chapter 13 Strings and Sorting Section 13.1 Finding a Substring with index Section 13.2 Manipulating a Substring with substr Section 13.3 Formatting Data with sprintf Section 13.4 Advanced Sorting Section 13.5 Exercises Chapter 14 Process Management Section 14.1 The system Function Section 14.2 The exec Function Section 14.3 The Environment Variables Section 14.4 Using Backquotes to Capture Output Section 14.5 Processes as Filehandles Section 14.6 Getting Down and Dirty with fork Section 14.7 Sending and Receiving Signals Section 14.8 Exercises Chapter 15 Perl Modules Section 15.1 Finding Modules Section 15.2 Installing Modules Section 15.3 Using Simple Modules Section 15.4 Exercise Chapter 16 Some Advanced Perl Techniques Section 16.1 Trapping Errors with eval Section 16.2 Picking Items from a List with grep Section 16.3 Transforming Items from a List with map Section 16.4 Unquoted Hash Keys Section 16.5 Slices Section 16.6 Exercise Exercise Answers Section A.1 Answers to Chapter 2 Exercises Section A.2 Answers to Chapter 3 Exercises Section A.3 Answers to Chapter 4 Exercises Section A.4 Answers to Chapter 5 Exercises Section A.5 Answers to Chapter 6 Exercises Section A.6 Answers to Chapter 7 Exercises Section A.7 Answers to Chapter 8 Exercises Section A.8 Answers to Chapter 9 Exercises Section A.9 Answer to Chapter 10 Exercise Section A.10 Answers to Chapter 11 Exercises Section A.11 Answers to Chapter 12 Exercises Section A.12 Answers to Chapter 13 Exercises Section A.13 Answers to Chapter 14 Exercises Section A.14 Answer to Chapter 15 Exercise Section A.15 Answer to Chapter 16 Exercise Beyond the Llama Section B.1 Further Documentation Section B.2 Regular Expressions Section B.3 Packages Section B.4 Extending Perl's Functionality Section B.5 Some Important Modules Section B.6 Pragmas Section B.7 Databases Section B.8 Other Operators and Functions Section B.9 Mathematics Section B.10 Lists and Arrays Section B.11 Bits and Pieces Section B.12 Formats Section B.13 Networking and IPC Section B.14 Security Section B.15 Debugging Section B.16 The Common Gateway Interface (CGI) Section B.17 Command-Line Options Section B.18 Built-in Variables Section B.19 Syntax Extensions Section B.20 References Section B.21 Tied Variables Section B.22 Operator Overloading Section B.23 Dynamic Loading Section B.24 Embedding Section B.25 Converting Other Languages to Perl Section B.26 Converting find Command Lines to Perl Section B.27 Command-Line Options in Your Programs Section B.28 Embedded Documentation Section B.29 More Ways to Open Filehandles Section B.30 Locales and Unicode Section B.31 Threads and Forking Section B.32 Graphical User Interfaces (GUIs) Section B.33 And More Colophon About the Authors Colophon Index Learning Perl, Fourth Edition by Randal L Schwartz, Tom Phoenix, and brian d foy Copyright © 2005, 2001, 1997, 1993 O'Reilly Media, Inc 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 (safari.oreilly.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Editor: Tatiana Apandi and Allison Randal Production Editor: Matt Hutchinson Production Services: GEX, Inc Cover Designer: Edie Freedman Interior Designer: David Futato Printing History: November 1993: First Edition July 1997: Second Edition July 2001: Third Edition July 2005: Fourth Edition Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc Learning Perl, the image of a llama, and related trade dress are trademarks of O'Reilly Media, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O'Reilly Media, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein ISBN: 0-596-10105-8 [M] Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] packages, namespaces and parameters, lists empty length parentheses, non-capturing partial-evaluation operators passing arguments to subroutines PATH environment variable patterns anchors groups interpolating into matching parentheses quantifiers general quantifiers replacement strings test code Perl acquiring creation of current state ease of use popularity support Perl course instructors Perl identifier Perl Mongers group Perl newsgroups perldoc command permissions, directories persistence, match variables pop operator portability, #! line and POSIX module postdecrements postincrements Practical Extraction and Report Language pragmas constant diagnostics lib strict use strict vars warnings 2nd precedence, regular expressions preincrements print( ) operator printf arrays and formatted output and printing, sprintf function private variables, subroutines processes as filehandles environment variables exec function fork output, backquotes and shell avoidance system function program creation prototypes push operator Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] quantifiers general quantifiers greedy non-greedy qw shortcut, lists Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] range operator ( ) receiving signals recursive directory listing redo operator references regular expressions character classes flags /x further reading introduction match variables persistence matches /s binding operator case-insensitive m// multiline text metacharacters option modifiers combining parentheses pattern test code powerful precedence quantifiers greedy shortcuts, negating text case text file update text replacement, global text substitutions whitespace | (bar) renaming files return operator return values non-scalar subroutines reverse operator Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] s/// (substitution operator) delimiters scalar values Boolean values scalar variables assignment binary assignment operators interpolation undef scalar-producing expresisons, lists scalars context forcing list-producing expressions numbers floating-point literals format non-decimal integer literals scope of variables security taint checking sending signals shell, avoiding shift operator short-circuit operators signals, sending/receiving simple modules single-quoted string literals slices array slices hash slices sockets, networking and sort operator 2nd sort subroutine sorting hashes, by value multiple keys splice operator, arrays split operator sprintf function numbers and standard error stream (STDERR) standard input standard output 2nd stat function, file tests STDERR (standard error stream) strict pragma string repetition operator strings array interpolation to bit strings concatenation converting to/from numbers double-quoted string literals format string, conversions operators single-quoted string literals sort operator split operator substrings indexes and substr operator sub keyword subroutines ampersand and anonymous arguments passing calling defining modules parameter length position in file prototypes return operator return values sort subroutine variables, private substrings indexes and substr operator support symbolic links syntax extensions Sys::Hostname module system function System V IPC Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] taint checking ternary operator text file updates, regular expressions and regular expressions and case global replacements join function match multiline substitutions Text::Wrap module threads, support tied variables Time::Local module timestamps in directories tr/// operator transliteration, tr/// operator trapping errors, eval and Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] undef scalar variable undef values, elements of arrays Unicode support unless control structure else clause unquoted hash keys unshift operator until control structure unwinding hashes updating multiple files use strict pragma user input user-defined functions, subroutines Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] values hash assignment sorting hashes by values function, hashes variables built-in default environment PATH processes and global lexical variables blocks list value assignment match variables automatic naming scalar assignment interpolation scalar variables scope subroutines, private tied vars pragma vi void context Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] warn function warnings warnings pragma while control whitespace regular epxressions and word anchors writing modules ... Other books may teach you to program in Perl, but this book will turn you into a Perl programmer Learning Perl, 4th Edition By brian d foy, Tom Phoenix, Randal L Schwartz Publisher: O'Reilly Pub Date: July 2005 ISBN: 0-596-10105-8... Interior Designer: David Futato Printing History: November 1993: First Edition July 1997: Second Edition July 2001: Third Edition July 2005: Fourth Edition Nutshell Handbook, the Nutshell Handbook logo, and the... the information contained herein ISBN: 0-596-10105-8 [M] Preface Welcome to the fourth edition of Learning Perl If you're looking for the best way to spend your first 30 to 45 hours with the Perl programming language, you've found it