Book description
The World’s Easiest Perl 5 Tutorial—Updated for Today’s Applications and “Modern Perl” Best Practices
“When I look at my bookshelf, I see eleven books on Perl programming. Perl by Example, Third Edition, isn’t on the shelf; it sits on my desk, where I use it almost daily. I still think it is the best Perl book on the market for anyone—beginner or seasoned programmer—who uses Perl daily.”
—Bill Maples, Enterprise Network Support, Fidelity National Information Services
Perl by Example, Fifth Edition, is the proven, easy way to master Perl 5 programming. Legendary Silicon Valley programming instructor Ellie Quigley has fully updated and focused her classic text on today’s key Perl applications, especially automation, testing, data extraction, and legacy code maintenance. She has also revised this edition to reflect “modern Perl” practices that have emerged since Perl 5.10.
Quigley illuminates every technique with focused, classroom-tested code examples. For each example, she shows you code, input, and output, and provides detailed, line-by-line explanations of how the code generates that output. And her coverage is comprehensive, from basic syntax to regular expression handling, files, references, objects, working with databases, and much more…plus appendices that contain a complete list of functions and definitions, command-line switches, special variables, and popular modules.
New in This Edition
• Modern Perl approaches to using data types, operators, conditions, subroutines, packages, modules, references, pointers, files, objects, and more
• Many new examples, covering automation, testing, and data extraction
• A tutorial on writing object-oriented Perl with the Moose object system
• An introduction to Dancer, a powerful web application framework designed to replace CGI
• Updated code examples throughout
More than 50,000 sysadmins, power users, and developers have used this book’s previous editions to become expert Perl programmers, and you can, too–even if you’re completely new to Perl. Then, once you’re an expert, you’ll routinely return to this practical guide as the best source for reliable answers, solutions, and code. A more focused, quicker read than ever, this clear and practical guide will take you from your first Perl script to advanced applications. It’s the only Perl text you’ll need.
Ellie Quigley has taught scripting in Silicon Valley for more than twenty-five years. Her Perl and shell programming classes at the University of California, Santa Cruz Extension are part of Silicon Valley lore. Her other best-selling Prentice Hall books include UNIX® Shells by Example, Fourth Edition; PHP and MySQL by Example (with Marko Gargenta); and JavaScript by Example. A major player in developing UCSC’s Silicon Valley Extension program, she has created and customized courses for pioneering firms, including Xilinx, NetApp, Yahoo, and Juniper.
Table of contents
- Cover
- About This eBook
- Title Page
- Copyright Page
- Praise for Ellie Quigley’s Books
- Contents
- Preface
- Chapter 1. The Practical Extraction and Report Language
- Chapter 2. Perl Quick Start
- Chapter 3. Perl Scripts
- Chapter 4. Getting a Handle on Printing
-
Chapter 5. What’s in a Name?
- 5.1 More About Data Types
- 5.2 Scalars, Arrays, and Hashes
-
5.3 Array Functions
- 5.3.1 Adding Elements to an Array
- 5.3.2 Removing and Replacing Elements
- 5.3.3 Deleting Newlines
- 5.3.4 Searching for Elements and Index Values
- 5.3.5 Creating a List from a Scalar
- 5.3.6 Creating a Scalar from a List
- 5.3.7 Transforming an Array
- 5.3.8 Sorting an Array
- 5.3.9 Checking the Existence of an Array Index Value
- 5.3.10 Reversing an Array
- 5.4 Hash (Associative Array) Functions
- 5.5 What You Should Know
- 5.6 What’s Next?
- Exercise 5: The Funny Characters
-
Chapter 6. Where’s the Operator?
- 6.1 About Perl Operators—More Context
- 6.2 Mixing Types
-
6.3 Precedence and Associativity
- 6.3.1 Assignment Operators
- 6.3.2 Boolean
- 6.3.3 Relational Operators
- 6.3.4 Conditional Operators
- 6.3.5 Equality Operators
- 6.3.6 The Smartmatch Operator
- 6.3.7 Logical Operators (Short-Circuit Operators)
- 6.3.8 Logical Word Operators
- 6.3.9 Arithmetic Operators and Functions
- 6.3.10 Autoincrement and Autodecrement Operators
- 6.3.11 Bitwise Logical Operators
- 6.3.12 Range Operator
- 6.3.13 Special String Operators and Functions
- 6.4 What You Should Know
- 6.5 What’s Next?
- Exercise 6: Operator, Operator
- Chapter 7. If Only, Unconditionally, Forever
-
Chapter 8. Regular Expressions—Pattern Matching
- 8.1 What Is a Regular Expression?
- 8.2 Modifiers and Simple Statements with Regular Expressions
- 8.3 Regular Expression Operators
- 8.4 What You Should Know
- 8.5 What’s Next?
- Exercise 8: A Match Made in Heaven
-
Chapter 9. Getting Control—Regular Expression Metacharacters
- 9.1 The RegExLib.com Library
- 9.2 Regular Expression Metacharacters
- 9.3 Unicode
- 9.4 What You Should Know
- 9.5 What’s Next?
- Exercise 9: And the Search Goes On . . .
-
Chapter 10. Getting a Handle on Files
- 10.1 The User-Defined Filehandle
-
10.2 Reading from STDIN
- 10.2.1 Assigning Input to a Scalar Variable
- 10.2.2 The chop and chomp Functions
- 10.2.3 The read Function
- 10.2.4 The getc Function
- 10.2.5 Assigning Input to an Array
- 10.2.6 Assigning Input to a Hash
- 10.2.7 Opening for Writing
- 10.2.8 Win32 Binary Files
- 10.2.9 Opening for Appending
- 10.2.10 The select Function
- 10.2.11 File Locking with flock
- 10.2.12 The seek and tell Functions
- 10.2.13 Opening for Reading and Writing
- 10.2.14 Opening for Anonymous Pipes
- 10.3 Passing Arguments
- 10.4 File Testing
- 10.5 What You Should Know
- 10.6 What’s Next?
- Exercise 10: Getting a Handle on Things
-
Chapter 11. How Do Subroutines Function?
- 11.1 Subroutines/Functions
-
11.2 Passing Arguments and the @_ Array
- 11.2.1 Call-by-Reference and the @_ Array
- 11.2.2 Assigning Values from @_
- 11.2.3 Returning a Value
- 11.2.4 Scoping Operators: local, my, our, and state
- 11.2.5 Using the strict Pragma (my and our)
- 11.2.6 Putting It All Together
- 11.2.7 Prototypes
- 11.2.8 Context and Subroutines
- 11.2.9 Autoloading
- 11.2.10 BEGIN and END Blocks (Startup and Finish)
- 11.2.11 The subs Function
- 11.3 What You Should Know
- 11.4 What’s Next?
- Exercise 11: I Can’t Seem to Function Without Subroutines
-
Chapter 12. Does This Job Require a Reference?
- 12.1 What Is a Reference?
- 12.2 What You Should Know
- 12.3 What’s Next?
- Exercise 12: It’s Not Polite to Point!
-
Chapter 13. Modularize It, Package It, and Send It to the Library!
- 13.1 Before Getting Started
- 13.2 The Standard Perl Library
- 13.3 Modules from CPAN
- 13.4 Using Perlbrew and CPAN Minus
- 13.5 What You Should Know
- 13.6 What’s Next?
- Exercise 13: I Hid All My Perls in a Package
-
Chapter 14. Bless Those Things! (Object-Oriented Perl)
- 14.1 The OOP Paradigm
- 14.2 Perl Classes, Objects, and Methods—Relating to the Real World
- 14.3 Anonymous Subroutines, Closures, and Privacy
- 14.4 Inheritance
- 14.5 Plain Old Documentation—Documenting a Module
- 14.6 Using Objects from the Perl Library
- 14.7 What You Should Know
- 14.8 What’s Next?
- Exercise 14: What’s the Object of This Lesson?
-
Chapter 15. Perl Connects with MySQL
- 15.1 Introduction
- 15.2 What Is a Relational Database?
-
15.3 Getting Started with MySQL
- 15.3.1 Installing MySQL
- 15.3.2 Connecting to MySQL
- 15.3.3 Graphical User Tools
- 15.3.4 Finding the Databases
-
15.3.5 Getting Started with Basic Commands
- Creating a Database with MySQL
- Selecting a Database with MySQL
- Creating a Table in the Database
- Data Types
- Adding Another Table with a Primary Key
- Inserting Data into Tables
- Selecting Data from Tables—The SELECT Command
- Selecting by Columns
- Selecting All Columns
- The WHERE Clause
- Sorting Tables
- Joining Tables
- Deleting Rows
- Updating Data in a Table
- Altering a Table
- Dropping a Table
- Dropping a Database
-
15.4 What Is the Perl DBI?
- 15.4.1 Installing the DBD Driver
- 15.4.2 The DBI Class Methods
- 15.4.3 How to Use DBI
- 15.4.4 Connecting to and Disconnecting from the Database
- 15.4.5 Preparing a Statement Handle and Fetching Results
- 15.4.6 Getting Error Messages
- 15.4.7 The ? Placeholder and Parameter Binding
- 15.4.8 Handling Quotes
- 15.4.9 Cached Queries
- 15.5 Statements That Don’t Return Anything
- 15.6 Transactions
- 15.7 What’s Left?
- 15.8 What You Should Know
- 15.9 What’s Next?
- Exercise 15: Practicing Queries and Using DBI
-
Chapter 16. Interfacing with the System
-
16.1 System Calls
- 16.1.1 Directories and Files
- 16.1.2 Directory and File Attributes
- 16.1.3 Finding Directories and Files
- 16.1.4 Creating a Directory—The mkdir Function
- 16.1.5 Removing a Directory—The rmdir Function
- 16.1.6 Changing Directories—The chdir Function
- 16.1.7 Accessing a Directory via the Directory Filehandle
- 16.1.8 Permissions and Ownership
- 16.1.9 Hard and Soft Links
- 16.1.10 Renaming Files
- 16.1.11 Changing Access and Modification Times
- 16.1.12 File Statistics
- 16.1.13 Packing and Unpacking Data
- 16.2 Processes
- 16.3 Other Ways to Interface with the Operating System
- 16.4 Error Handling
- 16.5 Signals and the %SIG Hash
- 16.6 What You Should Know
- Exercise 16: Interfacing with the System
-
16.1 System Calls
- Appendix A. Perl Built-ins, Pragmas, Modules, and the Debugger
-
Appendix B. SQL Language Tutorial
- B.1 What Is SQL?
-
B.2 SQL Data Manipulation Language (DML)
-
B.2.1 The SELECT Command
- Select Specified Columns
- Select All Columns
- The SELECT DISTINCT Statement
- Limiting the Number of Lines in the Result Set with LIMIT
- The WHERE Clause
- Using Quotes
- Using the = and <> Operators
- What Is NULL?
- The > and < Operators
- The AND and OR Operators
- The LIKE and NOT LIKE Conditions
- Pattern Matching and the % Wildcard
- The _ Wildcard
- The BETWEEN Statement
- Sorting Results with ORDER BY
- B.2.2 The INSERT Command
- B.2.3 The UPDATE Command
- B.2.4 The DELETE Statement
-
B.2.1 The SELECT Command
- B.3 SQL Data Definition Language
- B.4 SQL Functions
- B.5 Appendix Summary
- B.6 What You Should Know
- Exercise B: Do You Speak My Language?
- Appendix C. Introduction to Moose (A Postmodern Object System for Perl 5)
- Appendix D. Perlbrew, CPAN, and cpanm
- Appendix E. Dancing with Perl
- Index
- Code Snippets
Product information
- Title: Perl by Example
- Author(s):
- Release date: December 2014
- Publisher(s): Addison-Wesley Professional
- ISBN: 9780133593068
You might also like
book
Perl Best Practices
Many programmers code by instinct, relying on convenient habits or a "style" they picked up early …
book
Perl One-Liners
Perl One-Liners showcases 130 short and compelling lines of code that do all sorts of handy, …
book
Beginning Perl
Everything beginners need to start programming with Perl Perl is the ever-popular, flexible, open source programming …
book
Perl Testing: A Developer's Notebook
Is there any sexier topic in software development than software testing? That is, besides game programming, …