Toggle navigation
See also
Home
Programming
Perl objects, references and modules
Appendix A. Answers to Exercises
Appendix A. Answers to Exercises
This appendix contains the answers to the exercises presented throughout the book.
Chapter 1. Introduction
1.1 What Should You Know Already?
1.2 What About All Those Footnotes?
1.3 What's with the Exercises?
1.4 What if I'm a Perl Course Instructor?
Chapter 2. Building Larger Programs
2.1 The Cure for the Common Code
2.2 Inserting Code with eval
2.3 Using do
2.4 Using require
2.5 require and @INC
2.6 The Problem of Namespace Collisions
2.7 Packages as Namespace Separators
2.8 Scope of a Package Directive
2.9 Packages and Lexicals
2.10 Exercises
Chapter 3. Introduction to References
3.1 Performing the Same Task on Many Arrays
3.2 Taking a Reference to an Array
3.3 Dereferencing the Array Reference
3.4 Dropping Those Braces
3.5 Modifying the Array
3.6 Nested Data Structures
3.7 Simplifying Nested Element References with Arrows
3.8 References to Hashes
3.9 Exercises
Chapter 4. References and Scoping
4.1 More than One Reference to Data
4.2 What if That Was the Name?
4.3 Reference Counting and Nested Data Structures
4.4 When Reference Counting Goes Bad
4.5 Creating an Anonymous Array Directly
4.6 Creating an Anonymous Hash
4.7 Autovivification
4.8 Autovivification and Hashes
4.9 Exercises
Chapter 5. Manipulating Complex Data Structures
5.1 Using the Debugger to View Complex Data
5.2 Viewing Complex Data with Data::Dumper
5.3 Storing Complex Data with Storable
5.4 The map and grep Operators
5.5 Using map
5.6 Applying a Bit of Indirection
5.7 Selecting and Altering Complex Data
5.8 Exercises
Chapter 6. Subroutine References
6.1 Referencing a Named Subroutine
6.2 Anonymous Subroutines
6.3 Callbacks
6.4 Closures
6.5 Returning a Subroutine from a Subroutine
6.6 Closure Variables as Inputs
6.7 Closure Variables as Static Local Variables
6.8 Exercise
Chapter 7. Practical Reference Tricks
7.1 Review of Sorting
7.2 Sorting with Indices
7.3 Sorting Efficiently
7.4 The Schwartzian Transform
7.5 Recursively Defined Data
7.6 Building Recursively Defined Data
7.7 Displaying Recursively Defined Data
7.8 Exercises
Chapter 8. Introduction to Objects
8.1 If We Could Talk to the Animals...
8.2 Introducing the Method Invocation Arrow
8.3 The Extra Parameter of Method Invocation
8.4 Calling a Second Method to Simplify Things
8.5 A Few Notes About @ISA
8.6 Overriding the Methods
8.7 Starting the Search from a Different Place
8.8 The SUPER Way of Doing Things
8.9 What to Do with @_
8.10 Where We Are So Far...
8.11 Exercises
Chapter 9. Objects with Data
9.1 A Horse Is a Horse, of Course of Courseor Is It?
9.2 Invoking an Instance Method
9.3 Accessing the Instance Data
9.4 How to Build a Horse
9.5 Inheriting the Constructor
9.6 Making a Method Work with Either Classes or Instances
9.7 Adding Parameters to a Method
9.8 More Interesting Instances
9.9 A Horse of a Different Color
9.10 Getting Your Deposit Back
9.11 Don't Look Inside the Box
9.12 Faster Getters and Setters
9.13 Getters That Double as Setters
9.14 Restricting a Method to Class-Only or Instance-Only
9.15 Exercise
Chapter 10. Object Destruction
10.1 Nested Object Destruction
10.2 Beating a Dead Horse
10.3 Indirect Object Notation
10.4 Additional Instance Variables in Subclasses
10.5 Using Class Variables
10.6 Weakening the Argument
10.7 Exercise
Chapter 11. Some Advanced Object Topics
11.1 UNIVERSAL Methods
11.2 Testing Your Objects for Good Behavior
11.3 AUTOLOAD as a Last Resort
11.4 Using AUTOLOAD for Accessors
11.5 Creating Getters and Setters More Easily
11.6 Multiple Inheritance
11.7 References to Filehandles
11.8 Exercise
Chapter 12. Using Modules
12.1 Sample Function-Oriented Interface: File::Basename
12.2 Selecting What to Import
12.3 Sample Object-Oriented Interface: File::Spec
12.4 A More Typical Object-Oriented Module: Math::BigInt
12.5 The Differences Between OO and Non-OO Modules
12.6 What use Is Doing
12.7 Setting the Path at the Right Time
12.8 Importing with Exporter
12.9 @EXPORT and @EXPORT_OK
12.10 Exporting in a Primarily OO Module
12.11 Custom Import Routines
12.12 Exercise
Chapter 13. Writing a Distribution
13.1 Starting with h2xs
13.2 Looking at the Templates
13.3 The Prototype Module Itself
13.4 Embedded Documentation
13.5 Controlling the Distribution with Makefile.PL
13.6 Alternate Installation Locations (PREFIX=...)
13.7 Trivial make test
13.8 Trivial make install
13.9 Trivial make dist
13.10 Using the Alternate Library Location
13.11 Exercise
Chapter 14. Essential Testing
14.1 What the Test Harness Does
14.2 Writing Tests with Test::Simple
14.3 Writing Tests with Test::More
14.4 Conditional Tests
14.5 More Complex Tests (Multiple Test Scripts)
14.6 Testing Things That Write to STDOUT and STDERR
14.7 Exercise
Chapter 15. Contributing to CPAN
15.1 The Comprehensive Perl Archive Network
15.2 Getting Prepared
15.3 Preparing Your Distribution
15.4 Uploading Your Distribution
15.5 Announcing the Module
15.6 Testing on Multiple Platforms
15.7 Consider Writing an Article or Giving a Talk
15.8 Exercise
Appendix A. Answers to Exercises
A.1 Answers for Chapter 2
A.2 Answers for Chapter 3
A.3 Answers for Chapter 4
A.4 Answers for Chapter 5
A.5 Answer for Chapter 6
A.6 Answers for Chapter 7
A.7 Answers for Chapter 8
A.8 Answer for Chapter 9
A.9 Answer for Chapter 10
A.10 Answer for Chapter 11
A.11 Answer for Chapter 12
A.12 Answers for Chapters 13-15
Remember the name: eTutorials.org
Copyright eTutorials.org 2008-2024. All rights reserved.