Programming Perl: Unmatched Power for Text Processing and Scripting

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Adopted as the undisputed Perl bible soon after the first edition appeared in 1991, Programming Perl is still the go-to guide for this highly practical language. Perl began life as a super-fueled text processing utility, but quickly evolved into a general purpose programming language that’s helped hundreds of thousands of programmers, system administrators, and enthusiasts, like you, get your job done.

In this much-anticipated update to "the Camel," three renowned Perl authors cover the language up to its current version, Perl 5.14, with a preview of features in the upcoming 5.16. In a world where Unicode is increasingly essential for text processing, Perl offers the best and least painful support of any major language, smoothly integrating Unicode everywhere—including in Perl’s most popular feature: regular expressions.

Important features covered by this update include:

  • New keywords and syntax
  • I/O layers and encodings
  • New backslash escapes
  • Unicode 6.0
  • Unicode grapheme clusters and properties
  • Named captures in regexes
  • Recursive and grammatical patterns
  • Expanded coverage of CPAN
  • Current best practices

Author(s): Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Edition: 4
Publisher: O'Reilly Media
Year: 2012

Language: English
Commentary: Revision History for the Fourth Edition: 2015-07-10 Fourth release
Pages: 1176
City: Sebastopol, CA
Tags: Perl; Perl Programming; Unicode; Data Structures; Packages; Modules; Perl Object System; Object-Oriented Programming; IPC; Interprocess Communication; Perl Debugger; CPAN; Secure Code; POD; Plain Old Documentation; Perl Culture; Standard Perl Library; Pragmatic Modules

Table of Contents
List of Tables
Preface
The Pursuit of Happiness
What’s New in This Edition
The Standard Distribution
Online Documentation
Navigating the Standard Manpages
Non-Perl Manpages
Offline Documentation
Additional Resources
Perl on the Web
Bug Reports
Conventions Used in This Book
Using Code Examples
Acknowledgments
Safari® Books Online
We’d Like to Hear from You
Part I. Overview
Chapter 1. An Overview of Perl
Getting Started
Natural and Artificial Languages
Variable Syntax
Singularities
Pluralities
Arrays
Hashes
Complexities
Simplicities
Verbs
An Average Example
How to Do It
Filehandles
Operators
Some Binary Arithmetic Operators
String Operators
Assignment Operators
Unary Arithmetic Operators
Logical Operators
Some Numeric and String Comparison Operators
Some File Test Operators
Control Structures
What Is Truth?
The if and unless statements
The given and when Statements
Looping Constructs
Conditional loops
The three-part loop
The foreach loop
Breaking out: next and last
Regular Expressions
Quantifiers
Minimal Matching
Nailing Things Down
Backreferences
List Processing
What You Don’t Know Won’t Hurt You (Much)
Part II. The Gory Details
Chapter 2. Bits and Pieces
Atoms
Molecules
Built-in Data Types
Variables
Names
Name Lookups
Scalar Values
Numeric Literals
String Literals
Pick Your Own Quotes
Or Leave Out the Quotes Entirely
Interpolating Array Values
“Here” Documents
Version Literals
Other Literal Tokens
Context
Scalar and List Context
Boolean Context
Void Context
Interpolative Context
List Values and Arrays
List Assignment
Array Length
Hashes
Typeglobs and Filehandles
Input Operators
Command Input (Backtick) Operator
Line Input (Angle) Operator
Filename Globbing Operator
Chapter 3. Unary and Binary Operators
Terms and List Operators (Leftward)
The Arrow Operator
Autoincrement and Autodecrement
Exponentiation
Ideographic Unary Operators
Binding Operators
Multiplicative Operators
Additive Operators
Shift Operators
Named Unary and File Test Operators
Relational Operators
Equality Operators
Smartmatch Operator
Smartmatching of Objects
Bitwise Operators
C-Style Logical (Short-Circuit) Operators
Range Operators
Conditional Operator
Assignment Operators
Comma Operators
List Operators (Rightward)
Logical and, or, not, and xor
C Operators Missing from Perl
Chapter 4. Statements and Declarations
Simple Statements
Compound Statements
if and unless Statements
The given Statement
The when Statement and Modifier
Loop Statements
while and until Statements
Three-Part Loops
foreach Loops
Loop Control
Bare Blocks as Loops
Loopy Topicalizers
The goto Operator
Paleolithic Perl Case Structures
The Ellipsis Statement
Global Declarations
Scoped Declarations
Scoped Variable Declarations
Lexically Scoped Variables: my
Persistent Lexically Scoped Variables: state
Lexically Scoped Global Declarations: our
Dynamically Scoped Variables: local
Pragmas
Controlling Warnings
Controlling the Use of Globals
Chapter 5. Pattern Matching
The Regular Expression Bestiary
Pattern-Matching Operators
Pattern Modifiers
The m// Operator (Matching)
The s/// Operator (Substitution)
Modifying strings en passant
Modifying arrays en masse
When a global substitution just isn’t global enough
The tr/// Operator (Transliteration)
Metacharacters and Metasymbols
Metasymbol Tables
Specific Characters
Wildcard Metasymbols
Character Classes
Bracketed Character Classes
Classic Perl Character Class Shortcuts
Character Properties
POSIX-Style Character Classes
Quantifiers
Positions
Beginnings: The \A and ^ Assertions
Endings: The \z, \Z, and $ Assertions
Boundaries: The \b and \B Assertions
Progressive Matching
Where You Left Off: The \G Assertion
Grouping and Capturing
Capturing
Named capture groups
Grouping Without Capturing
Scoped Pattern Modifiers
Alternation
Staying in Control
Letting Perl Do the Work
Variable Interpolation
When backslashes happen
The qr/PATTERN/modifiers quote regex operator
The Regex Compiler
The Little Engine That /Could(n’t)?/
Fancy Patterns
Lookaround Assertions
Possessive Groups
Programmatic Patterns
Generated patterns
Substitution evaluations
Match-time code evaluation
Match-time pattern interpolation
Conditional interpolation
Recursive Patterns
Grammatical Patterns
Grammars
Defining Your Own Assertions
Alternate Engines
Chapter 6. Unicode
Show, Don’t Tell
Getting at Unicode Data
The Encode Module
A Case of Mistaken Identity
Graphemes and Normalization
Comparing and Sorting Unicode Text
Using the uca with Perl’s sort
Locale Sorting
More Goodies
Custom Regex Boundaries
Building Character
References
Chapter 7. Subroutines
Syntax
Semantics
Tricks with Parameter Lists
Error Indications
Scoping Issues
Passing References
Prototypes
Inlining Constant Functions
Care with Prototypes
Prototypes of Built-in Functions
Subroutine Attributes
The method Attribute
The lvalue Attribute
Chapter 8. References
What Is a Reference?
Creating References
The Backslash Operator
Anonymous Data
The anonymous array composer
The anonymous hash composer
The anonymous subroutine composer
Object Constructors
Handle References
Symbol Table References
Implicit Creation of References
Using Hard References
Using a Variable As a Variable Name
Using a block As a Variable Name
Using the Arrow Operator
Using Object Methods
Pseudohashes
Other Tricks You Can Do with Hard References
Closures
Closures as function templates
Nested subroutines
Symbolic References
Braces, Brackets, and Quoting
References Don’t Work As Hash Keys
Garbage Collection, Circular References, and Weak References
Chapter 9. Data Structures
Arrays of Arrays
Creating and Accessing a Two-Dimensional Array
Growing Your Own
Access and Printing
Slices
Common Mistakes
Hashes of Arrays
Composition of a Hash of Arrays
Generation of a Hash of Arrays
Access and Printing of a Hash of Arrays
Arrays of Hashes
Composition of an Array of Hashes
Generation of an Array of Hashes
Access and Printing of an Array of Hashes
Hashes of Hashes
Composition of a Hash of Hashes
Generation of a Hash of Hashes
Access and Printing of a Hash of Hashes
Hashes of Functions
More Elaborate Records
Composition, Access, and Printing of More Elaborate Records
Composition, Access, and Printing of Even More Elaborate Records
Generation of a Hash of Complex Records
Saving Data Structures
Chapter 10. Packages
Symbol Tables
Qualified Names
The Default Package
Changing the Package
Autoloading
Chapter 11. Modules
Loading Modules
Unloading Modules
Creating Modules
Naming Modules
A Sample Module
Module Privacy and the Exporter
Exporting without using Exporter’s import method
Version checking
Managing unknown symbols
Tag-handling utility functions
Overriding Built-in Functions
Chapter 12. Objects
Brief Refresher on Object-Oriented Lingo
Perl’s Object System
Method Invocation
Method Invocation Using the Arrow Operator
Method Invocation Using Indirect Objects
Syntactic Snafus with Indirect Objects
Package-Quoted Classes
Object Construction
Inheritable Constructors
Initializers
Class Inheritance
Inheritance Through @ISA
Alternate Method Searching
Accessing Overridden Methods
UNIVERSAL: The Ultimate Ancestor Class
Method Autoloading
Private Methods
Instance Destructors
Garbage Collection with destroy Methods
Managing Instance Data
Generating Accessors with Autoloading
Generating Accessors with Closures
Using Closures for Private Objects
New Tricks
Managing Class Data
The Moose in the Room
Summary
Chapter 13. Overloading
The overload Pragma
Overload Handlers
Overloadable Operators
The Copy Constructor (=)
When an Overload Handler Is Missing (nomethod and fallback)
Overloading Constants
Public Overload Functions
Inheritance and Overloading
Runtime Overloading
Overloading Diagnostics
Chapter 14. Tied Variables
Tying Scalars
Scalar-Tying Methods
Magical Counter Variables
Cycling Through Values
Magically Banishing $_
Tying Arrays
Array-Tying Methods
Notational Convenience
Tying Hashes
Hash-Tying Methods
Tying Filehandles
Filehandle-Tying Methods
Creative Filehandles
A Subtle Untying Trap
Tie Modules on CPAN
Part III. Perl as Technology
Chapter 15. Interprocess Communication
Signals
Signalling Process Groups
Reaping Zombies
Timing Out Slow Operations
Blocking Signals
Signal Safety
Files
File Locking
Passing Filehandles
Pipes
Anonymous Pipes
Talking to Yourself
Bidirectional Communication
Named Pipes
System V IPC
Sockets
Networking Clients
Networking Servers
Message Passing
Chapter 16. Compiling
The Life Cycle of a Perl Program
Compiling Your Code
Executing Your Code
Compiler Backends
Code Generators
The Bytecode Generator
The C Code Generators
Code Development Tools
Avant-Garde Compiler, Retro Interpreter
Chapter 17. The Command-Line Interface
Command Processing
#! and Quoting on Non-Unix Systems
Location of Perl
Switches
Environment Variables
Chapter 18. The Perl Debugger
Using the Debugger
Debugger Commands
Stepping and Running
Breakpoints
Tracing
Display
Locating Code
Actions and Command Execution
Miscellaneous Commands
Debugger Customization
Editor Support for Debugging
Customizing with Init Files
Debugger Options
Unattended Execution
Debugger Support
Writing Your Own Debugger
Profiling Perl
Devel::DProf
Devel::NYTProf
Chapter 19. CPAN
History
A Tour of the Repository
Creating a MiniCPAN
The CPAN Ecosystem
PAUSE
Searching CPAN
Testing
Bug Tracking
rt.cpan.org
Other bug tracking
perlbug
rt.perl.org
Installing CPAN Modules
By Hand
CPAN Clients
cpan
cpanp
cpanminus
Creating CPAN Distributions
Starting Your Distribution
h2xs
Distribution::Cooker
Module::Starter
Dist::Zilla
Testing Your Modules
Internal testing
External testing
Part IV. Perl as Culture
Chapter 20. Security
Handling Insecure Data
Detecting and Laundering Tainted Data
Cleaning Up Your Environment
Accessing Commands and Files Under Reduced Privileges
Defeating Taint Checking
Handling Timing Glitches
Unix Kernel Security Bugs
Handling Race Conditions
Temporary Files
Handling Insecure Code
Changing Root
Safe Compartments
Restricting namespace access
Restricting operator access
Safe examples
Code Masquerading As Data
Chapter 21. Common Practices
Common Goofs for Novices
Universal Blunders
Frequently Ignored Advice
C Traps
Shell Traps
Python Traps
Ruby Traps
Java Traps
Efficiency
Time Efficiency
Space Efficiency
Programmer Efficiency
Maintainer Efficiency
Porter Efficiency
User Efficiency
Programming with Style
Fluent Perl
Program Generation
Generating Other Languages in Perl
Generating Perl in Other Languages
Source Filters
Chapter 22. Portable Perl
Newlines
Endianness and Number Width
Files and Filesystems
System Interaction
Interprocess Communication (IPC)
External Subroutines (XS)
Standard Modules
Dates and Times
Internationalization
Style
Chapter 23. Plain Old Documentation
Pod in a Nutshell
Verbatim Paragraphs
Command Paragraphs
Flowed Text
Pod Translators and Modules
Writing Your Own Pod Tools
Pod Pitfalls
Documenting Your Perl Programs
Chapter 24. Perl Culture
History Made Practical
Perl Poetry
Virtues of the Perl Programmer
Events
Getting Help
Part V. Reference Material
Chapter 25. Special Names
Special Names Grouped by Type
Regular Expression Special Variables
Per-Filehandle Variables
Per-Package Special Variables
Program-Wide Special Variables
Per-Package Special Filehandles
Per-Package Special Functions
Special Variables in Alphabetical Order
Chapter 26. Formats
String Formats
Binary Formats
pack
Repetition
Other modifiers
More examples
unpack
Picture Formats
Format Variables
Footers
Accessing Formatting Internals
Chapter 27. Functions
Perl Functions by Category
Perl Functions in Alphabetical Order
abs
accept
alarm
atan2
bind
binmode
bless
break
caller
chdir
chmod
chomp
chop
chown
chr
chroot
close
closedir
connect
continue
cos
crypt
dbmclose
dbmopen
defined
delete
die
do (block)
do (file)
do (subroutine)
dump
each
eof
eval
exec
exists
exit
exp
_ _FILE_ _
fc
fcntl
fileno
flock
fork
format
formline
getc
getgrent
getgrgid
getgrnam
gethostbyaddr
gethostbyname
gethostent
getlogin
getnetbyaddr
getnetbyname
getnetent
getpeername
getpgrp
getppid
getpriority
getprotobyname
getprotobynumber
getprotoent
getpwent
getpwnam
getpwuid
getservbyname
getservbyport
getservent
getsockname
getsockopt
glob
gmtime
goto
grep
hex
import
index
int
ioctl
join
keys
kill
last
lc
lcfirst
length
_ _LINE_ _
link
listen
local
localtime
lock
log
lstat
m//
map
mkdir
msgctl
msgget
msgrcv
msgsnd
my
new
next
no
oct
open
opendir
ord
our
pack
package
_ _PACKAGE_ _
pipe
pop
pos
print
printf
prototype
push
q/STRING/
quotemeta
rand
read
readdir
readline
readlink
readpipe
recv
redo
ref
rename
require
reset
return
reverse
rewinddir
rindex
rmdir
s///
say
scalar
seek
seekdir
select (output filehandle)
select (ready file descriptors)
semctl
semget
semop
send
setpgrp
setpriority
setsockopt
shift
shmctl
shmget
shmread
shmwrite
shutdown
sin
sleep
socket
socketpair
sort
splice
split
sprintf
sqrt
srand
stat
state
study
sub
substr
symlink
syscall
sysopen
sysread
sysseek
system
syswrite
tell
telldir
tie
tied
time
times
tr///
truncate
uc
ucfirst
umask
undef
unlink
unpack
unshift
untie
use
utime
values
vec
wait
waitpid
wantarray
warn
write
y//
Chapter 28. The Standard Perl Library
Library Science
A Tour of the Perl Library
Roll Call
The Future of the Standard Perl Library
Wandering the Stacks
Chapter 29. Pragmatic Modules
attributes
autodie
autouse
base
bigint
bignum
bigrat
blib
bytes
charnames
Custom Character Names
Runtime Lookups
constant
Restrictions on constant
deprecate
diagnostics
encoding
feature
fields
filetest
if
inc::latest
integer
less
lib
locale
mro
open
ops
overload
overloading
parent
re
sigtrap
Signal Handlers
Predefined Signal Lists
Other Arguments to sigtrap
Examples of sigtrap
sort
strict
strict "refs"
strict "vars"
strict "subs"
subs
threads
utf8
vars
version
vmsish
exit
hushed
status
time
warnings
User-Defined Pragmas
Glossary
Index of Perl Modules in This Book
Index