Table of Contents
Foreword; Preface; Finding Perl Resources; Conventions Used in This Book; Comments and Questions; Acknowledgments; Chapter 1: Introduction; 1.1 History of TPJ; 1.2 Computer Science and Perl Programming; Beginner Concepts; Chapter 2: All About Arrays; 2.1 Basics; 2.2 Positions; 2.3 Position Versus Count; 2.4 Foreach Loops; 2.5 The Reverse and Sort Functions; 2.6 Slices; 2.7 Adding and Deleting Values; 2.8 Lists to Strings and Back Again; 2.9 Putting It All Together; Chapter 3: Perfect Programming; 3.1 Warnings with -w; 3.2 The strict Pragma; 3.3 Tainting and Safe; 3.4 Checking Return Values; 3.5 Planning for Failure; 3.6 The Perl Debugger; 3.7 The Perl Profiler; 3.8 Stack Traces; Chapter 4: Precedence; 4.1 What Is Precedence?; 4.2 Rules and More Rules; 4.3 An Explosion of Rules; 4.4 Precedence Traps and Surprises; 4.5 List Operators and Unary Operators; 4.6 Complete Rules of Precedence; 4.7 How to Remember All the Rules; 4.8 Quiz; 4.9 Answers; Chapter 5: The Birth of a One-Liner; Chapter 6: Comparators, Sorting, and Hashes; 6.1 Sorting; 6.2 Sorting Hashes; 6.3 Efficient Sorting; 6.4 Further Reading; Chapter 7: What Is Truth?; 7.1 The undef Function; 7.2 Back to Truth; 7.3 Truth in Context; 7.4 Applications; 7.5 Conclusion; Chapter 8: Using Object-Oriented Modules; 8.1 Modules and Their Functional Interfaces; 8.2 Modules with Object-Oriented Interfaces; 8.3 What Can You Do with Objects?; 8.4 What’s in an Object?; 8.5 What Is an Object Value?; 8.6 So Why Do Some Modules Use Objects?; Chapter 9: Unreal Numbers; 9.1 A Surprising Program; 9.2 The Right Way; Chapter 10: CryptoContext; 10.1 Context; 10.2 Prototypes; 10.3 Subroutine Calls; 10.4 Putting Them All Together; 10.5 Conclusion; Chapter 11: References; 11.1 Who Needs Complicated Data Structures?; 11.2 The Solution; 11.3 Making References; 11.4 Using References; 11.5 An Example; 11.6 Solution; 11.7 The Rest; 11.8 In Summary; Chapter 12: Perl Heresies; 12.1 Don’t Use -w; 12.2 Don’t Use Regular Expressions Just Because They’re Cool; 12.3 Don’t Always Use Modules; 12.4 Partial Solutions Are Okay; Regular Expressions; Chapter 13: Understanding Regular Expressions, Part I; 13.1 The Story of Fred; 13.2 Reality Check; 13.3 Regular Expression Background; 13.4 Perl Regex Engine Basics; 13.5 The First Real Rule of Regexes; 13.6 A Single Match Attempt; 13.7 Options, Options, Options; 13.8 How the Path Is Chosen; 13.9 That’s Pretty Much It; Chapter 14: Understanding Regular Expressions, Part II; 14.1 Knowing Versus Knowing on Paper; 14.2 Efficiency; 14.3 Benchmarking; 14.4 Conclusion; Chapter 15: Understanding Regular Expressions, Part III; Chapter 16: Nibbling Strings; 16.1 The Problem; 16.2 Going on a Diet; Chapter 17: How Regexes Work; 17.1 Machines; 17.2 Blank Arrows; 17.3 Rules Again; 17.4 How to Turn a Regex into a Penny Machine; 17.5 What Do You Mean, Done?; 17.6 The Regex Module; 17.7 Implications for Perl; 17.8 What About Backreferences?; 17.9 Internals of Regex.pm; 17.10 Lies; 17.11 Other Directions; 17.12 Bibliography; Computer Science; Chapter 18: Infinite Lists; 18.1 Hamming’s Problem; 18.2 Streams; 18.3 Hamming’s Problem Revisited; 18.4 Dataflow Programming; 18.5 Other Directions; 18.6 References; Chapter 19: Compression; 19.1 Morse Code; 19.2 Ambiguous Codes; 19.3 Huffman Coding; 19.4 The Code; 19.5 The Rub; 19.6 Another Rub; 19.7 Other Methods; 19.8 Other Directions; 19.9 Bibliography; Chapter 20: Memoization; 20.1 Recursive Functions; 20.2 The Memoize Module; 20.3 Module Internals; 20.4 Some Other Applications of Memoization; 20.5 When Memoizing Doesn’t Work; 20.6 Bibliography; Chapter 21: Parsing; 21.1 A Sample Parse; 21.2 Formal Grammars; 21.3 The Different Types of Parsers; 21.4 Building a Parser with Parse::RecDescent; 21.5 How Parse::RecDescent Works; 21.6 An In-Depth Example; 21.7 Advanced Features of Parse::RecDescent; 21.8 Practical Applications of Parsing; 21.9 Limitations of Parse::Recdescent; 21.10 More Information; 21.11 Acknowledgments; Chapter 22: Trees and Game Trees; 22.1 What Is a Tree?; 22.2 Formal Definition; 22.3 Markup Language Trees; 22.4 Building Your Own Trees; 22.5 An Implementation: Game Trees for Alak; 22.6 References; Chapter 23: B_Trees; 23.1 A Review of Binary Trees; 23.2 The Problem with Binary Trees; 23.3 B-Trees Are Always Balanced; 23.4 A Guided Tour of the Program; 23.5 Moving Down; 23.6 Moving Up; 23.7 Details; 23.8 Other Directions; 23......9 Bibliography; Chapter 24: Making Life and Death Decisions with Perl; 24.1 Probability Theory; 24.2 Whoa!; 24.3 Perl; 24.4 Last Words; Chapter 25: Information Retrieval; 25.1 Text Searches on Manual Pages; 25.2 The Implementation; 25.3 Relevance Feedback; 25.4 Advanced” Search Operators; 25.5 Conclusion; 25.6 References; Chapter 26: Randomness; 26.1 Congruential Generators; 26.2 Choosing the Seed; 26.3 LFSRs; 26.4 References; Chapter 27: Random Number Generators and XS; 27.1 Random Versus Pseudorandom Numbers; 27.2 Linear Congruential Generators Revisited; 27.3 A Better Generator for Perl; 27.4 Bridging C and Perl with XS; 27.5 Acknowledgments; 27.6 References; Programming Techniques; Chapter 28: Suffering from Buffering; 28.1 What Is Buffering?; 28.2 Surprise!; 28.3 Disabling Inappropriate Buffering; 28.4 Hot and Not Hot; 28.5 Other Perils of Buffering; 28.6 Flushing on Command; 28.7 Other Directions; 28.8 Summary; Chapter 29: Scoping; 29.1 Package Variables; 29.2 The Current Package; 29.3 Package Variable Trivia; 29.4 Lexical Variables; 29.5 local and my; 29.6 What Good Is local?; 29.7 When to Use my and When to Use local; 29.8 Other Properties of my Variables; 29.9 my Variable Trivia; 29.10 Declarations; 29.11 Summary; Chapter 30: Seven Useful Uses of local; 30.1 1. Special Variables; 30.2 2. Localized Filehandles; 30.3 3. The First Class Filehandle Trick; 30.4 4. Aliases; 30.5 5. Dynamic Scope; 30.6 6. Dynamic Scope Revisited; 30.7 7. Perl 4 and Other Relics; 30.8 Summary; Chapter 31: Parsing Command-Line Options; 31.1 Option Parsing Conventions; 31.2 The Simplest Way; 31.3 The Easy Way; 31.4 The Advanced Way; 31.5 Other Option Handling Modules; Chapter 32: Building a Better Hash with tie; 32.1 Introduction; 32.2 The Problem; 32.3 Discussion; 32.4 Attempted Solutions; 32.5 A Working Data Structure; 32.6 Implementation; 32.7 Implementing a Tied Hash; 32.8 Using a Tied Hash; 32.9 Testing; 32.10 Optimizations; 32.11 Making It a Module; 32.12 Summing Up; 32.13 References; Chapter 33: Source Filters; 33.1 Concepts; 33.2 Using Filters; 33.3 Writing a Source Filter; 33.4 The Debug Filter; 33.5 Conclusion; Chapter 34: Overloading; 34.1 Defining Your Own Types; 34.2 Adding Methods to the Date Class; 34.3 A Minor Problem; 34.4 Introducing Overloading; 34.5 Overloading More Methods; 34.6 Overloading and Associativity; 34.7 Full Overloading Implementations; 34.8 Automatically Generating Overloaded Methods; 34.9 The Fallback Mechanism; 34.10 Overloading and Inheritance; 34.11 Limitations of Operator Overloading; 34.12 Conclusion; 34.13 References; Chapter 35: Building Objects Out of Arrays; 35.1 OO Basics; 35.2 Arrays Are Faster; 35.3 Arrays Use Less Space; 35.4 Arrays Can Prevent Attribute Collisions; 35.5 Arrays Can Prevent Misspellings; 35.6 Disadvantages; 35.7 Other Approaches; Chapter 36: Hiding Objects with Closures; 36.1 A Simple Example; 36.2 Closures; 36.3 What About Inheritance?; 36.4 Conclusion; Chapter 37: Multiple Dispatch in Perl; 37.1 Multiple Dispatch; 37.2 Multiple Dispatch via Tests-in-Methods”; 37.3 Multiple Dispatch via a Table; 37.4 Comparing the Two Approaches; 37.5 Dynamic Dispatch Tables; 37.6 The Class::Multimethods Module; Software Development; Chapter 38: Using Other Languages from Perl; 38.1 Introducing Inline.pm; 38.2 A More Complex Example; 38.3 Calling C Functions from Perl; 38.4 Manipulating Perl’s Stack; 38.5 How Inline Works; 38.6 Creating Perl Extensions; 38.7 Inline::Config; 38.8 XS and SWIG; 38.9 Using Perl as C’s Memory Manager; 38.10 Benchmarks; Chapter 39: SWIG; 39.1 Hooks by Hand; 39.2 Wrapping a C Function; 39.3 Interface Files; 39.4 An In-Depth Example: Emulating top; 39.5 The top Emulator; 39.6 Conclusion; Chapter 40: Benchmarking; 40.1 The Trouble with time( ); 40.2 Better Resolution with times; 40.3 The Benchmark Module; 40.4 Example: Summing an Array; 40.5 Conclusion; Chapter 41: Building Software with Cons; 41.1 Make Doesn’t Do the Right Thing; 41.2 The Solution: Cons; 41.3 Summary; Chapter 42: MakeMaker; 42.1 Reasons to Use MakeMaker; 42.2 h2xs; 42.3 Components of Makefile.PL; 42.4 A Deeper Example; 42.5 Advanced Makefile Features; 42.6 MakeMaker and Installation of Modules; 42.7 perllocal.pod; Chapter 43: Autoloading Perl Code; 43.1 Why Autoload?; 43.2 Using the AutoLoader; 43.3 How Autoloading Works; 43.4 AutoSplitting Your Module; 43.5 AutoLoading Scripts; 43.6 AutoLoading C Programs; 43.7 Summary; Chapter 44: Debugging and Devel::; 44.1 Runtime Examination of Data; 44.2 Profiling and Coverage Testing; 44.3 Reference Manipulation; 44.4 Helping C and C++ Programmers; 44.5 Rolling Your Own; 44.6 Which Should You Use?; Networking; Chapter 45: Email with Attachments; 45.1 What Is MIME, and Why Do I Care?; 45.2 How Does MIME Encode Data?; 45.3 Multiple Pieces of MIME; 45.4 How to Create a Mime Message; 45.5 An Alternate Route; 45.6 A Full-Blown Example; 45.7 Conclusion; Chapter 46: Sending Mail Without sendmail; 46.1 Some Email Background; 46.2 The Mail Itself; 46.3 Sending Mail in Six Easy Steps; 46.4 What Next?; Chapter 47: Filtering Mail; 47.1 What Is It?; 47.2 A Very Simple Mail Filter; 47.3 Separating Mail into Folders; 47.4 Mail and News; 47.5 A Complete Filter; 47.6 Caveats; 47.7 Conclusion; Chapter 48: Net::Telnet; 48.1 The Problem; 48.2 The Solution; 48.3 Telnetting the Hard Way; 48.4 Telnetting the Easy Way; 48.5 Telnetting the Easiest Way; 48.6 Special Considerations; 48.7 Other Features; Chapter 49: Microsoft Office; 49.1 Background; 49.2 The Problem; 49.3 The Solution; 49.4 Wait, There’s More; Chapter 50: Client-Server Applications; 50.1 Using the inetd Super-Daemon; 50.2 A Standalone Server; 50.3 A Threaded Server; 50.4 Launching Standalone Servers from inetd; 50.5 Further Information; Chapter 51: Managing Streaming Audio; 51.1 Playlists, Streams, and ID3 Tags; 51.2 Apache::MP3; 51.3 Conclusion; Chapter 52: A 74-Line Ip Telephone; 52.1 Sound Cards and /dev/dsp; 52.2 The Simple Version; 52.3 Adding an MP3 Encoder; 52.4 Summary; 52.5 References; Chapter 53: Controlling Modems; 53.1 Initializing Your Modem; 53.2 Getting Your Modem to Dial; 53.3 To Block or Not to Block?; 53.4 What’s Next?; 53.5 Afterword; 53.6 References; Chapter 54: Using Usenet from Perl; 54.1 Finding Newsgroups; 54.2 Retrieving Articles; 54.3 Posting Articles; Chapter 55: Transferring Files with FTP; 55.1 A Simple Example; 55.2 Multiple FTP Connections; 55.3 Transferring Files Between Servers; Chapter 56: Spidering an FTP Site; 56.1 Motivation; 56.2 Net::FTP; 56.3 Downloading a File (the Simple Case); 56.4 Recursion; 56.5 Downloading a File Tree (the Recursive Case); 56.6 Uploading a File (the Simple Case); 56.7 Uploading a File Tree (the Recursive Case); 56.8 Applications; Chapter 57: DNS Updates with Perl; 57.1 DNS Basics; 57.2 DNS Servers; 57.3 Dynamic Update; 57.4 Setting Up Your Nameserver; 57.5 Delegating the Zone; 57.6 Using Net::DNS::Update; 57.7 Paths for Futher Exploration; Databases; Chapter 58: DBI; 58.1 The Architecture of DBI; 58.2 Why DBI?; 58.3 The Modules; 58.4 Handles; 58.5 Resources; 58.6 Sample Code; Chapter 59: Using DBI with Microsoft Access; 59.1 The Win32-Access-ODBC-DBI::DBD Checklist:; 59.2 References; Chapter 60: DBI Caveats; 60.1 DBI and Loops; 60.2 Placeholders; 60.3 Fetches; 60.4 Bind Columns; 60.5 Error Checking; 60.6 Transactions; 60.7 References; Chapter 61: Beyond Hardcoded Database Applications with DBIx::Recordset; 61.1 CRUD Without SQL; 61.2 Sample Usage; 61.3 A DBI Version; 61.4 Conclusion; Chapter 62: Win32::ODBC; 62.1 Win32::ODBC Basics; 62.2 Demystifying SQL; 62.3 Installing Win32::ODBC; 62.4 Getting Started; 62.5 Debugging; 62.6 CRUD; 62.7 Transactions; 62.8 Data Sources; 62.9 Data Dictionary; 62.10 Conclusion; Chapter 63: Net::LDAP; 63.1 What Is LDAP?; 63.2 Setting Up an OpenLDAP Server; 63.3 Loading Data into the Directory; 63.4 A Searchable Web Interface to Manage Your Directory; 63.5 Where LDAP Is Going; 63.6 References; Chapter 64: Web Databases the Genome Project Way; 64.1 The ACEDB Database; 64.2 ACEDB Objects and Classes; 64.3 Accessing ACEDB from Perl; 64.4 ACEDB Meets the Web; 64.5 Registering ACEDB Displays; 64.6 Conclusions; 64.7 References; Chapter 65: Spreadsheet::WriteExcel; 65.1 Using Spreadsheet::WriteExcel; 65.2 How the Spreadsheet::WriteExcel Module Works; 65.3 Alternative Ways of Writing to Excel; 65.4 Reading from Excel; 65.5 Win32::OLE; 65.6 Obtaining Spreadsheet::WriteExcel; 65.7 References; Internals; Chapter 66: How to Improve Perl; Chapter 67: Components of the Perl Distribution; 67.1 The Components of Perl; 67.2 Summary; Chapter 68: Basic Perl Anatomy; 68.1 How Perl Works; 68.2 Lexical Analysis; 68.3 Parsing; 68.4 Compilation; 68.5 Execution; 68.6 Perl Subsystems; 68.7 For Further Reading; Chapter 69: Lexical Analysis; 69.1 Tokenizing; 69.2 Perl’s Lexer; 69.3 Lexer Variables; 69.4 Tokenizing Considerations; 69.5 Further Information; Chapter 70: Debugging Perl Programs with -D; 70.1 What -D Does for You; 70.2 Trace Execution with -Dt; 70.3 Stack Snapshots with -Ds; 70.4 Syntax Tree Dump with -Dx; 70.5 Regular Expression Parsing and Execution with -Dr; 70.6 Method and Overloading Resolution with -Do; 70.7 Context (Loop) Stack Processing with -Dl; 70.8 Tokenizing and Parsing with -Dp; 70.9 Other -D Debugging Flags; Chapter 71: Microperl; 71.1 Bootstrapping; 71.2 Building Microperl; 71.3 How Microperl Works; 71.4 Practical Uses for Microperl; 71.5 Problems; 71.6 Future Work; Colophon;