Publisher: O'Reilly Media
Final Release Date: August 1998
Pages: 800
The Perl Cookbook is a comprehensive collection of problems, solutions, and practical examples for anyone programming in Perl. Topics range from beginner questions to techniques that even the most experienced of Perl programmers will learn from. More than just a collection of tips and tricks, the Perl Cookbook is the long-awaited companion volume to Programming Perl, filled with previously unpublished Perl arcana.The Perl Cookbook contains thousands upon thousands of examples ranging from brief one-liners to complete applications. Covered topic areas spread across nearly four hundred separate "recipes," including:
- Manipulation of strings, numbers, dates, arrays, and hashes
- Reading, writing, and updating text and binary files
- Pattern matching and text substitutions
- Subroutines, libraries, and modules
- References, data structures, objects, and classes
- Signals and exceptions
- Accessing text, hashes, and SQL databases
- Screen addressing, menus, and graphical applications
- Managing other processes
- Writing secure scripts
- Client-server programming
- Internet applications programming with mail, news, ftp, and telnet
These recipes were rigorously reviewed by scores of the best minds inside and outside Perl, foremost of which was Larry Wall, the creator of Perl himself.The Perl Cookbook is written by Tom Christiansen, Perl evangelist and coauthor of the bestselling Programming Perl and Learning Perl; and Nathan Torkington, Perl trainer and co-maintainer of the Perl Frequently Asked Questions list.
|
-
Chapter 1 Strings -
Introduction -
Accessing Substrings -
Establishing a Default Value -
Exchanging Values Without Using Temporary Variables -
Converting Between ASCII Characters and Values -
Processing a String One Character at a Time -
Reversing a String by Word or Character -
Expanding and Compressing Tabs -
Expanding Variables in User Input -
Controlling Case -
Interpolating Functions and Expressions Within Strings -
Indenting Here Documents -
Reformatting Paragraphs -
Escaping Characters -
Trimming Blanks from the Ends of a String -
Parsing Comma-Separated Data -
Soundex Matching -
Program: fixstyle -
Program: psgrep -
Chapter 2 Numbers -
Introduction -
Checking Whether a String Is a Valid Number -
Comparing Floating-Point Numbers -
Rounding Floating-Point Numbers -
Converting Between Binary and Decimal -
Operating on a Series of Integers -
Working with Roman Numerals -
Generating Random Numbers -
Generating Different Random Numbers -
Making Numbers Even More Random -
Generating Biased Random Numbers -
Doing Trigonometry in Degrees, not Radians -
Calculating More Trigonometric Functions -
Taking Logarithms -
Multiplying Matrices -
Using Complex Numbers -
Converting Between Octal and Hexadecimal -
Putting Commas in Numbers -
Printing Correct Plurals -
Program: Calculating Prime Factors -
Chapter 3 Dates and Times -
Introduction -
Finding Today’s Date -
Converting DMYHMS to Epoch Seconds -
Converting Epoch Seconds to DMYHMS -
Adding to or Subtracting from a Date -
Difference of Two Dates -
Day in a Week/Month/Year or Week Number -
Parsing Dates and Times from Strings -
Printing a Date -
High-Resolution Timers -
Short Sleeps -
Program: hopdelta -
Chapter 4 Arrays -
Introduction -
Specifying a List In Your Program -
Printing a List with Commas -
Changing Array Size -
Doing Something with Every Element in a List -
Iterating Over an Array by Reference -
Extracting Unique Elements from a List -
Finding Elements in One Array but Not Another -
Computing Union, Intersection, or Difference of Unique Lists -
Appending One Array to Another -
Reversing an Array -
Processing Multiple Elements of an Array -
Finding the First List Element That Passes a Test -
Finding All Elements in an Array Matching Certain Criteria -
Sorting an Array Numerically -
Sorting a List by Computable Field -
Implementing a Circular List -
Randomizing an Array -
Program: words -
Program: permute -
Chapter 5 Hashes -
Introduction -
Adding an Element to a Hash -
Testing for the Presence of a Key in a Hash -
Deleting from a Hash -
Traversing a Hash -
Printing a Hash -
Retrieving from a Hash in Insertion Order -
Hashes with Multiple Values Per Key -
Inverting a Hash -
Sorting a Hash -
Merging Hashes -
Finding Common or Different Keys in Two Hashes -
Hashing References -
Presizing a Hash -
Finding the Most Common Anything -
Representing Relationships Between Data -
Program: dutree -
Chapter 6 Pattern Matching -
Introduction -
Copying and Substituting Simultaneously -
Matching Letters -
Matching Words -
Commenting Regular Expressions -
Finding the Nth Occurrence of a Match -
Matching Multiple Lines -
Reading Records with a Pattern Separator -
Extracting a Range of Lines -
Matching Shell Globs as Regular Expressions -
Speeding Up Interpolated Matches -
Testing for a Valid Pattern -
Honoring Locale Settings in Regular Expressions -
Approximate Matching -
Matching from Where the Last Pattern Left Off -
Greedy and Non-Greedy Matches -
Detecting Duplicate Words -
Expressing AND, OR, and NOT in a Single Pattern -
Matching Multiple-Byte Characters -
Matching a Valid Mail Address -
Matching Abbreviations -
Program: urlify -
Program: tcgrep -
Regular Expression Grabbag -
Chapter 7 File Access -
Introduction -
Opening a File -
Opening Files with Unusual Filenames -
Expanding Tildes in Filenames -
Making Perl Report Filenames in Errors -
Creating Temporary Files -
Storing Files Inside Your Program Text -
Writing a Filter -
Modifying a File in Place with Temporary File -
Modifying a File in Place with -i Switch -
Modifying a File in Place Without a Temporary File -
Locking a File -
Flushing Output -
Reading from Many Filehandles Without Blocking -
Doing Non-Blocking I/O -
Determining the Number of Bytes to Read -
Storing Filehandles in Variables -
Caching Open Output Filehandles -
Printing to Many Filehandles Simultaneously -
Opening and Closing File Descriptors by Number -
Copying Filehandles -
Program: netlock -
Program: lockarea -
Chapter 8 File Contents -
Introduction -
Reading Lines with Continuation Characters -
Counting Lines (or Paragraphs or Records) in a File -
Processing Every Word in a File -
Reading a File Backwards by Line or Paragraph -
Trailing a Growing File -
Picking a Random Line from a File -
Randomizing All Lines -
Reading a Particular Line in a File -
Processing Variable-Length Text Fields -
Removing the Last Line of a File -
Processing Binary Files -
Using Random-Access I/O -
Updating a Random-Access File -
Reading a String from a Binary File -
Reading Fixed-Length Records -
Reading Configuration Files -
Testing a File for Trustworthiness -
Program: tailwtmp -
Program: tctee -
Program: laston -
Chapter 9 Directories -
Introduction -
Getting and Setting Timestamps -
Deleting a File -
Copying or Moving a File -
Recognizing Two Names for the Same File -
Processing All Files in a Directory -
Globbing, or Getting a List of Filenames Matching a Pattern -
Processing All Files in a Directory Recursively -
Removing a Directory and Its Contents -
Renaming Files -
Splitting a Filename into Its Component Parts -
Program: symirror -
Program: lst -
Chapter 10 Subroutines -
Introduction -
Accessing Subroutine Arguments -
Making Variables Private to a Function -
Creating Persistent Private Variables -
Determining Current Function Name -
Passing Arrays and Hashes by Reference -
Detecting Return Context -
Passing by Named Parameter -
Skipping Selected Return Values -
Returning More Than One Array or Hash -
Returning Failure -
Prototyping Functions -
Handling Exceptions -
Saving Global Values -
Redefining a Function -
Trapping Undefined Function Calls with AUTOLOAD -
Nesting Subroutines -
Program: Sorting Your Mail -
Chapter 11 References and Records -
Introduction -
Taking References to Arrays -
Making Hashes of Arrays -
Taking References to Hashes -
Taking References to Functions -
Taking References to Scalars -
Creating Arrays of Scalar References -
Using Closures Instead of Objects -
Creating References to Methods -
Constructing Records -
Reading and Writing Hash Records to Text Files -
Printing Data Structures -
Copying Data Structures -
Storing Data Structures to Disk -
Transparently Persistent Data Structures -
Program: Binary Trees -
Chapter 12 Packages, Libraries, and Modules -
Introduction -
Defining a Module’s Interface -
Trapping Errors in require or use -
Delaying use Until Run Time -
Making Variables Private to a Module -
Determining the Caller’s Package -
Automating Module Clean-Up -
Keeping Your Own Module Directory -
Preparing a Module for Distribution -
Speeding Module Loading with SelfLoader -
Speeding Up Module Loading with Autoloader -
Overriding Built-In Functions -
Reporting Errors and Warnings Like Built-Ins -
Referring to Packages Indirectly -
Using h2ph to Translate C #include Files -
Using h2xs to Make a Module with C Code -
Documenting Your Module with Pod -
Building and Installing a CPAN Module -
Example: Module Template -
Program: Finding Versions and Descriptions of Installed Modules -
Chapter 13 Classes, Objects, and Ties -
Introduction -
Constructing an Object -
Destroying an Object -
Managing Instance Data -
Managing Class Data -
Using Classes as Structs -
Cloning Objects -
Calling Methods Indirectly -
Determining Subclass Membership -
Writing an Inheritable Class -
Accessing Overridden Methods -
Generating Attribute Methods Using AUTOLOAD -
Solving the Data Inheritance Problem -
Coping with Circular Data Structures -
Overloading Operators -
Creating Magic Variables with tie -
Chapter 14 Database Access -
Introduction -
Making and Using a DBM File -
Emptying a DBM File -
Converting Between DBM Files -
Merging DBM Files -
Locking DBM Files -
Sorting Large DBM Files -
Treating a Text File as a Database Array -
Storing Complex Data in a DBM File -
Persistent Data -
Executing an SQL Command Using DBI and DBD -
Program: ggh—Grep Netscape Global History -
Chapter 15 User Interfaces -
Introduction -
Parsing Program Arguments -
Testing Whether a Program Is Running Interactively -
Clearing the Screen -
Determining Terminal or Window Size -
Changing Text Color -
Reading from the Keyboard -
Ringing the Terminal Bell -
Using POSIX termios -
Checking for Waiting Input -
Reading Passwords -
Editing Input -
Managing the Screen -
Controlling Another Program with Expect -
Creating Menus with Tk -
Creating Dialog Boxes with Tk -
Responding to Tk Resize Events -
Removing the DOS Shell Window with Windows Perl/Tk -
Program: Small termcap program -
Program: tkshufflepod -
Chapter 16 Process Management and Communication -
Introduction -
Gathering Output from a Program -
Running Another Program -
Replacing the Current Program with a Different One -
Reading or Writing to Another Program -
Filtering Your Own Output -
Preprocessing Input -
Reading STDERR from a Program -
Controlling Input and Output of Another Program -
Controlling the Input, Output, and Error of Another Program -
Communicating Between Related Processes -
Making a Process Look Like a File with Named Pipes -
Sharing Variables in Different Processes -
Listing Available Signals -
Sending a Signal -
Installing a Signal Handler -
Temporarily Overriding a Signal Handler -
Writing a Signal Handler -
Catching Ctrl-C -
Avoiding Zombie Processes -
Blocking Signals -
Timing Out an Operation -
Program: sigrand -
Chapter 17 Sockets -
Introduction -
Writing a TCP Client -
Writing a TCP Server -
Communicating over TCP -
Setting Up a UDP Client -
Setting Up a UDP Server -
Using UNIX Domain Sockets -
Identifying the Other End of a Socket -
Finding Your Own Name and Address -
Closing a Socket After Forking -
Writing Bidirectional Clients -
Forking Servers -
Pre-Forking Servers -
Non-Forking Servers -
Writing a Multi-Homed Server -
Making a Daemon Server -
Restarting a Server on Demand -
Program: backsniff -
Program: fwdport -
Chapter 18 Internet Services -
Introduction -
Simple DNS Lookups -
Being an FTP Client -
Sending Mail -
Reading and Posting Usenet News Messages -
Reading Mail with POP3 -
Simulating Telnet from a Program -
Pinging a Machine -
Using Whois to Retrieve Information from the InterNIC -
Program: expn and vrfy -
Chapter 19 CGI Programming -
Introduction -
Writing a CGI Script -
Redirecting Error Messages -
Fixing a 500 Server Error -
Writing a Safe CGI Program -
Making CGI Scripts Efficient -
Executing Commands Without Shell Escapes -
Formatting Lists and Tables with HTML Shortcuts -
Redirecting to a Different Location -
Debugging the Raw HTTP Exchange -
Managing Cookies -
Creating Sticky Widgets -
Writing a Multiscreen CGI Script -
Saving a Form to a File or Mail Pipe -
Program: chemiserie -
Chapter 20 Web Automation -
Introduction -
Fetching a URL from a Perl Script -
Automating Form Submission -
Extracting URLs -
Converting ASCII to HTML -
Converting HTML to ASCII -
Extracting or Removing HTML Tags -
Finding Stale Links -
Finding Fresh Links -
Creating HTML Templates -
Mirroring Web Pages -
Creating a Robot -
Parsing a Web Server Log File -
Processing Server Logs -
Program: htmlsub -
Program: hrefsub -
Colophon |
- Title:
- Perl Cookbook
- By:
- Tom Christiansen, Nathan Torkington
- Publisher:
- O'Reilly Media
- Formats:
-
- Print
- Safari Books Online
- Print:
- August 1998
- Pages:
- 800
- Print ISBN:
- 978-1-56592-243-3
- | ISBN 10:
- 1-56592-243-3
|
-
Tom Christiansen Tom Christiansen is a freelance consultant specializing in Perl training and writing. After working for several years for TSR Hobbies (of Dungeons and Dragons fame), he set off for college where he spent a year in Spain and five in America, dabbling in music, linguistics, programming, and some half-dozen different spoken languages. Tom finally escaped UW-Madison with B.A.s in Spanish and computer science and an M.S. in computer science. He then spent five years at Convex as a jack-of-all-trades working on everything from system administration to utility and kernel development, with customer support and training thrown in for good measure. Tom also served two terms on the USENIX Association Board of directors. With over fifteen years' experience in UNIX system administration and programming, Tom presents seminars internationally. Living in the foothills above Boulder, Colorado, surrounded by mule deer, skunks, and the occasional mountain lion and black bear, Tom takes summers off for hiking, hacking, birding, music making, and gaming. View Tom Christiansen's full profile page. -
Nathan Torkington Nathan Torkington is a banjo player, father, and husband. His crimes in the computing community include: coauthor of the Perl Cookbook, editor for O'Reilly and Associates, content coordinator for the Open Source Convention and Perl Conference, and project manager for perl6. View Nathan Torkington's full profile page. |
Colophon Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal featured on the cover of Perl Cookbook is a bighorn sheep. Bighorn sheep (Ovis canadensis) are wild sheep noted, not surprisingly, for their large, curved horns. Male bighorns grow to approximately 5 feet long and 40 inches tall to the shoulder and weigh up to 350 pounds. Their horns measure up to 18 inches in circumference and 4 feet long and can weigh up to 30 pounds. Despite their bulk, bighorns are adept at negotiating mountainous terrains. With their sharp, cloven hooves they can walk on ledges as thin as two inches. They have excellent eyesight that enables them to locate footholds and to accurately judge distances between ledges. They can jump as far as 20 feet from ledge to ledge.Competition for ewes is intense and often leads to fierce battles that can continue for a full day. During the battle two rams race at each other at speeds of up to 20 miles an hour, clashing their horns together. The skull of the bighorn sheep is double-layered to provide protection from these blows. Horn size is a significant factor in determining rank, and rams will only fight other rams with an equivalently sized horn. Mature males usually stay apart from the females and young. In these "bachelor flocks" the lower-ranking males often play the part of ewes and behave in a submissive manner toward the dominant males. The dominant male, in turn, behaves like a courting ram and mounts the lower-ranking male. This behavior is believed to enable the rams to live together without rank disputes that might otherwise drive the lower-ranking males out of the flock.Bighorns can be found in the Rocky Mountains from Canada to Colorado and in the desert from California to west Texas and Mexico. They are threatened with extinction as a result of disease, habitat reduction, and hunting. Clairemarie Fisher O'Leary was the production editor and project manager for this book. Steven Kleinedler copyedited, Kristin Barendsen and Kristine Simmons proofread, and Jane Ellin and Sheryl Avruch provided quality control reviews. Trisha Manoni, Sebastian Banker, and Kimo Carter provided production assistance. Seth Maislin wrote the index. The illustrations were created in Macromedia Freehand 7.0 by Robert Romano. Edie Freedman designed the cover, using a 19th-century engraving from the Dover Pictorial Archive. The cover layout was produced with Quark XPress 3.32 using the ITC Garamond font. The inside layout was designed by Edie Freedman and modified by Nancy Priest and implemented in FrameMaker by Mike Sierra. The text and heading fonts are ITC Garamond Light and Garamond Book. This colophon was written by Clairemarie Fisher O'Leary. |
|
Table of Contents
|
Product Details
|
About the Author
|
Colophon
|
 |
|
 |
|
|
|
Recommended for You
|
Recently Viewed
|
 |
|
By Johan Vromans
July 2002
By John Callender
October 2001
By Sean M. Burke
June 2002
Ebook
:
$31.99
Print & Ebook
:
$43.99
Print
:
$39.99
|
Customer Reviews
6/22/2010 5.0One of the best Perl books By fdegir from Stockholm About Me Designer, Developer - Accurate
- Concise
- Easy to understand
- Helpful examples
- Well-written
By Wortwart from Undisclosed By Al Rizo-Patron from Undisclosed 2/24/2003 (1 of 1 customers found this review helpful) By Al Rizo-Patron from Undisclosed By Pete Nelson from Undisclosed 3/19/2001 (1 of 1 customers found this review helpful) By John Powell from Undisclosed By Ismo Kallioniemi from Undisclosed By Michael Turley from Undisclosed By Michael Turley from Undisclosed
|
|
|