Learning Perl Objects, References, and Modules

Front Cover
"O'Reilly Media, Inc.", Jun 9, 2003 - Computers - 224 pages

Perl is a versatile, powerful programming language used in a variety of disciplines, ranging from system administration to web programming to database manipulation. One slogan of Perl is that it makes easy things easy and hard things possible. This book is about making the leap from the easy things to the hard ones.Learning Perl Objects, References & Modules offers a gentle but thorough introduction to advanced programming in Perl. Written by the authors of the best-selling Learning Perl, this book picks up where that book left off. Topics include:

  • Packages and namespaces
  • References and scoping
  • Manipulating complex data structures
  • Object-oriented programming
  • Writing and using modules
  • Contributing to CPAN
Following the successful format of Learning Perl, each chapter in the book is designed to be small enough to be read in just an hour or two, ending with a series of exercises to help you practice what you've learned. To use the book, you just need to be familiar with the material in Learning Perl and have ambition to go further.Perl is a different language to different people. It is a quick scripting tool for some, and a fully-featured object-oriented language for others. It is used for everything from performing quick global replacements on text files, to crunching huge, complex sets of scientific data that take weeks to process. Perl is what you make of it. But regardless of what you use Perl for, this book helps you do it more effectively, efficiently, and elegantly.Learning Perl Objects, References & Modules is about learning to use Perl as a programming language, and not just a scripting language. This is the book that separates the Perl dabbler from the Perl programmer.
 

Selected pages

Contents

Exercises
98
Objects with Data
99
Invoking an Instance Method
100
Accessing the Instance Data
101
How to Build a Horse
102
Making a Method Work with Either Classes or Instances
103
Adding Parameters to a Method
104
More Interesting Instances
105

The Problem of Namespace Collisions
11
Packages as Namespace Separators
12
Scope of a Package Directive
14
Packages and Lexicals
15
Introduction to References
17
Taking a Reference to an Array
19
Dereferencing the Array Reference
20
Dropping Those Braces
21
Modifying the Array
22
Nested Data Structures
23
Simplifying Nested Element References with Arrows
25
References to Hashes
26
Exercises
28
References and Scoping
30
What if That Was the Name?
31
Reference Counting and Nested Data Structures
32
When Reference Counting Goes Bad
34
Creating an Anonymous Array Directly
35
Creating an Anonymous Hash
38
Autovivification
40
Autovivification and Hashes
42
Exercises
44
Manipulating Complex Data Structures
45
Dumper
50
Storing Complex Data with Storable
51
The map and grep Operators
53
Using map
55
Applying a Bit of Indirection
56
Selecting and Altering Complex Data
58
Exercises
59
Subroutine References
61
Anonymous Subroutines
65
Callbacks
67
Closures
68
Returning a Subroutine from a Subroutine
70
Closure Variables as Inputs
73
Exercise
75
Practical Reference Tricks
77
Sorting with Indices
78
Sorting Efficiently
79
The Schwartzian Transform
81
Recursively Defined Data
82
Displaying Recursively Defined Data
85
Exercises
86
Introduction to Objects
88
If We Could Talk to the Animals
89
Introducing the Method Invocation Arrow
90
The Extra Parameter of Method Invocation
91
Calling a Second Method to Simplify Things
92
A Few Notes About ISA
93
Overriding the Methods
94
Starting the Search from a Different Place
96
The SUPER Way of Doing Things
97
A Horse of a Different Color
106
Dont Look Inside the Box
108
Faster Getters and Setters
109
Restricting a Method to ClassOnly or InstanceOnly
110
Object Destruction
112
Beating a Dead Horse
117
Indirect Object Notation
118
Additional Instance Variables in Subclasses
119
Using Class Variables
121
Weakening the Argument
122
Exercise
125
Some Advanced Object Topics
126
Testing Your Objects for Good Behavior
127
AUTOLOAD as a Last Resort
128
Using AUTOLOAD for Accessors
129
Creating Getters and Setters More Easily
130
Multiple Inheritance
132
References to Filehandles
133
Exercise
135
Using Modules
137
Selecting What to Import
138
MathBiglnt
139
The Differences Between OO and NonOO Modules
140
Setting the Path at the Right Time
141
Importing with Exporter
143
EXPORT and EXPORT_OK
144
Exporting in a Primarily OO Module
145
Custom Import Routines
147
Writing a Distribution
148
Starting with h2xs
149
The Prototype Module Itself
152
Embedded Documentation
154
Controlling the Distribution with MakefilePL
158
Alternate Installation Locations PREFIX
159
Trivial make test
160
Trivial make install
161
Trivial make dist
162
Exercise
163
Essential Testing
164
What the Test Harness Does
166
Simple
167
More
168
Conditional Tests
172
More Complex Tests Multiple Test Scripts
173
Exercise
174
Contributing to CPAN
175
Getting Prepared
176
Uploading Your Distribution
177
Announcing the Module
178
Exercise
179
Answers to Exercises
181
Index
197
Copyright

Other editions - View all

Common terms and phrases

About the author (2003)

Tom Phoenix has been working in the field of education since 1982. After more than thirteen years of dissections, explosions, work with interesting animals, and high-voltage sparks during his work at a science museum, he started teaching Perl classes for Stonehenge Consulting Services, where he's worked since 1996. Since then, he has traveled to many interesting locations, so you might see him soon at a Perl Mongers' meeting. When he has time, he answers questions on Usenet's comp.lang.perl.misc and comp.lang.perl.moderated newsgroups, and contributes to the development and usefulness of Perl. Besides his work with Perl, Perl hackers, and related topics, Tom spends his time on amateur cryptography and speaking Esperanto. His home is in Portland, Oregon.

Bibliographic information