Home Page Icon
Home Page
Table of Contents for
Advanced Perl Programming
Close
Advanced Perl Programming
by Sriram Srinivasan
Advanced Perl Programming
Advanced Perl Programming
Preface
The Case for Scripting
Why Perl?
What Must I Know?
Language Syntax
The Perl Interpreter
Technology Areas
The Book’s Approach
A Note to the Expert
Systems View
Examples
FTP
FTPMAIL
Conventions
Resources
Perl Resources
We’d Like to Hear from You
Acknowledgments
1. Data References and Anonymous Storage
Referring to Existing Variables
A Reference Is Just Another Scalar
Dereferencing
References to Scalars
References to Arrays
References to Hashes
Confusion About Precedence
Shortcuts with the Arrow Notation
No Automatic Dereferencing
Using References
Passing Arrays and Hashes to Subroutines
Performance Efficiency
References to Anonymous Storage
Dereferencing Multiple Levels of Indirection
A More General Rule
Trojan horses
Nested Data Structures
Implicit Creation of Complex Structures
Final Shortcut: Omit Arrows Between Subscripts
Querying a Reference
Symbolic References
A View of the Internals
Reference Counts
Array/Hash References Versus Element References
References in Other Languages
Tcl
Python
C/C++
Java
Resources
2. Implementing Complex Data Structures
User-Defined Structures
Example: Matrices
Hash of Hashes Representation
Other Matrix Representations
Professors, Students, Courses
Representation
Pass the Envelope
Data Representation
Print All Entries for a Given Year
Print All Entries Sorted by Year
Print a Specific Entry, Given a Year and Category
Pretty-Printing
Resources
3. Typeglobs and Symbol Tables
Perl Variables, Symbol Table, and Scoping
Lexical Variables
Lexical Versus Dynamic Scoping
When would you ever need to use local?
Typeglobs
Temporary Aliases
Using Typeglob Aliases
Efficient parameter passing
Aliasing on command lines
Friendly predefined variables with aliases
Aliasing Problem: Variable Suicide
Typeglobs and References
Selective Aliasing
Constants
Naming Anonymous Subroutines
References to Typeglobs
Filehandles, Directory Handles, and Formats
I/O Redirection
Passing Filehandles to Subroutines
Localizing Filehandles
Strings as Handles
4. Subroutine References and Closures
Subroutine References
References to Named Subroutines
References to Anonymous Subroutines
Dereferencing Subroutine References
Symbolic References
Using Subroutine References
Dispatch Table
Signal Handlers
Expression Plotting
Closures
Closures, Behind the Scenes
Using Closures
Using Closures as “Smart” Callbacks
Iterators and Streams
Random number generation
Closures Versus Objects
Comparisons to Other Languages
Tcl
Python
C++
Java
Resources
5. Eval
The String Form: Expression Evaluation
The Block Form: Exception Handling
Standard Modules
Exception.pm
exceptions.pl
Watch Your Quotes
Using Eval for Expression Evaluation
Expression Evaluation in Substitutions
Using Eval for Efficiency
A Fast Multipattern grep
Extracting Columns from a File
Using Eval for Time-Outs
Eval in Other Languages
Tcl (Tool Command Language)
Python
C / C++
Java
Resources
6. Modules
Basic Package
Packages and Variables
Symbolic References
Packages and Files
Load Path
Package Initialization and Destruction
Privacy
Enforcing Privacy
Importing Symbols
How Do use and Exporter Work?
Nesting Packages
Autoloading
Accessing the Symbol Table
Language Comparisons
Tcl
Python
C/C++
Java
7. Object-Oriented Programming
OO: An Introduction
Objects in Perl
Attributes
Unique Identity
Behavior
The Need for Polymorphism
Class Methods and Attributes
Detour: The indirect notation
The Need for Inheritance
Overriding base classes
Object Destruction
Accessor Methods
UNIVERSAL
Searching for Methods
Recap of Conventions
Example
Comparison with Other OO Languages
Tcl
Python
C++ and Java
Resources
8. Object Orientation: The Next Few Steps
Efficient Attribute Storage
ObjectTemplate: Attribute Storage Using Arrays
ObjectTemplate internals overview
ObjectTemplate implementation
Suggested changes to ObjectTemplate
Attribute Storage Using Typeglobs
Delegation
On Inheritance
Attribute Inheritance
Implementation Inheritance
Interface Inheritance
Using Composition Instead
Resources
9. Tie
Tying Scalars
Example: Stopwatch
tie works with anonymous values
Tying Arrays
TIEARRAY Example: File as an Array
Tying Hashes
Tying Filehandles
Example: Monitoring Variables
Comparisons with Other Languages
Tcl
Python
C++
Java
10. Persistence
Persistence Issues
Streamed Data
FreezeThaw
Data::Dumper
Storable
Record-Oriented Approach
DBM
MLDBM
Berkeley DB
Relational Databases
DBI (Database Interface)
Basic SQL accesses
Select
Query meta-data
Transactions
Special functions
What DBI does not provide
Win32::ODBC
Resources
11. Implementing Object Persistence
Adaptor: An Introduction
Design Notes
Design Goals
Object Encapsulation
Object-Adaptor Protocol
Multivalued Attributes and Database Mapping
Inheritance and Database Mapping
Object Identity
Object Associations
Uniqueness of Objects in Memory
Queries
Schema Evolution
Implementation
Adaptor::File
Storing objects
Retrieving objects
Query processing
Adaptor::DBI
Storing objects
Queries
Resources
12. Networking with Sockets
Networking Primer
Socket API and IO::Socket
Receiver
Sender
Bidirectional Communications
Handling Multiple Clients
Multiple Threads of Execution
Multiplexing Using select
Blocking looms again
Nonblocking Filehandles
Real-World Servers
IO Objects and Filehandles
Prebuilt Client Modules
Net::FTP
Net::POP3
Resources
13. Networking: Implementing RPC
Msg: Messaging Toolkit
Msg Implementation
Msg: Send-side routines
Msg: Receive-side routines
Msg: Support for nonblocking I/O
Msg: Event loop routines
Remote Procedure Calls (RPC)
Using RPC
RPC: Implementation
Resources
14. User Interfaces with Tk
Introduction to GUIs, Tk, and Perl/Tk
Starting with Perl/Tk
GUI Forms: The Easy Way
Widget Tour
Widget Properties
Fonts
Images
Colors
Labels and Buttons
Radiobuttons and Checkbuttons
Canvas
Text and Entry
Inserting text at absolute positions
Inserting text at logical positions
Insertion with relative indexing
Using tags to change properties of text ranges
The entry widget
Text widget and ties
Listbox
Frame
Menus
Scrollbars and Scrolling
Custom scrolling
Scale
HList
Geometry Management
Packer
Grid
Timers
Event Bindings
Multiple Bindings
Event Details
Event Loops
Resources
15. GUI Example: Tetris
Introduction to Tetris
Design
User Interface
Data Structures
Implementation
16. GUI Example: Man Page Viewer
man and perlman
Implementation
Showing Man Pages
Searching for Text
Screen Layout
Resources
17. Template-DrivenCode Generation
On Code Generation
Jeeves Example
Oh, and Can You Do This Too?
Jeeves Overview
Advantages of This Architecture
Intermediate Perl Code
Jeeves Implementation
AST Module
Template Parser
Jeeves Driver
Sample Specification Parser
Resources
18. Extending Perl: A First Course
Writing an Extension: Overview
The Extension Process
SWIG or XS?
Example: Fractals with Perl
Fractals Using SWIG
Fractals Using XS
SWIG Features
XS Features
What Does xsubpp Do?
Default and Optional Parameters
Modifying Parameters
Special Code
C++ Code
Degrees of Freedom
A Detour into Fractals
Resources
19. Embedding Perl:The Easy Way
Why Embed?
Embedding Overview
Examples
Adding Extensions
Resources
20. Perl Internals
Reading the Source
Architecture
Perl Objects
Multiple interpreters
Translator
Inside opcodes
Compilation and code generation stages
Security features
Executor
Perl Value Types
Scalar Values
Using this API
Inside SVs
SVs and object pointers
Array Values (AV)
Inside AVs
Hash Values (HVs)
Inside HVs
Glob Values and Symbol Tables
Inside glob values and symbol tables
Code Values
Inside CV
How local and my work
Closures
Objects versus closures
Magic Variables
Stacks and Messaging Protocol
Calling a Perl Subroutine
The Called Side: Hand-Coding an XSUB
Returning a variable list of results
Ensuring that the stack is big enough
Inside Other Stacks
Meaty Extensions
Anatomy of an XS Extension
XS Typemaps: An Introduction
Object Interface Using XS Typemaps
Making XS Typemaps More Generic
C++ Objects and XS Typemaps
Memory Management Using XS
Recommended memory allocation and deallocation routines
SWIG Typemaps
Easy Embedding API
A Peek into the Future
Resources
A. Tk Widget Reference
Button
Radiobutton
Checkbutton
Canvas
Text
Entry
Listbox
Menus
Scrollbars and Scrolling
Scale
HList — Hierarchical List
B. Syntax Summary
References
Nested Data Structures
Closures
Modules
Objects
Dynamic Behavior
Exception Handling
Meta-Information
Typeglobs
Filehandles, Formats
Index
Colophon
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Preface
Advanced Perl Programming
Sriram Srinivasan
Editor
Andy Oram
Copyright © 1997 O'Reilly Media, Inc.
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset