O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Higher-Order Perl

Book Description

Most Perl programmers were originally trained as C and Unix programmers, so the Perl programs that they write bear a strong resemblance to C programs. However, Perl incorporates many features that have their roots in other languages such as Lisp. These advanced features are not well understood and are rarely used by most Perl programmers, but they are very powerful. They can automate tasks in everyday programming that are difficult to solve in any other way. One of the most powerful of these techniques is writing functions that manufacture or modify other functions. For example, instead of writing ten similar functions, a programmer can write a general pattern or framework that can then create the functions as needed according to the pattern. For several years Mark Jason Dominus has worked to apply functional programming techniques to Perl. Now Mark brings these flexible programming methods that he has successfully taught in numerous tutorials and training sessions to a wider audience.

* Introduces powerful programming methods—new to most Perl programmers—that were previously the domain of computer scientists
* Gradually builds up confidence by describing techniques of progressive sophistication
* Shows how to improve everyday programs and includes numerous engaging code examples to illustrate the methods

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright
  4. Dedication
  5. Preface
  6. Table of Contents
  7. Chapter 1: Recursion and Callbacks
    1. 1.1 DECIMAL TO BINARY CONVERSION
    2. 1.2 FACTORIAL
    3. 1.3 THE TOWER OF HANOI
    4. 1.4 HIERARCHICAL DATA
    5. 1.5 APPLICATIONS AND VARIATIONS OF DIRECTORY WALKING
    6. 1.6 FUNCTIONAL VERSUS OBJECT-ORIENTED PROGRAMMING
    7. 1.7 HTML
    8. 1.8 WHEN RECURSION BLOWS UP
  8. Chapter 2: Dispatch Tables
    1. 2.1 CONFIGURATION FILE HANDLING
    2. 2.2 CALCULATOR
  9. Chapter 3: Caching and Memoization
    1. 3.1 CACHING FIXES RECURSION
    2. 3.2 INLINE CACHING
    3. 3.3 GOOD IDEAS
    4. 3.4 MEMOIZATION
    5. 3.5 THE MEMOIZE MODULE
    6. 3.6 CAVEATS
    7. 3.7 KEY GENERATION
    8. 3.8 CACHING IN OBJECT METHODS
    9. 3.9 PERSISTENT CACHES
    10. 3.10 ALTERNATIVES TO MEMOIZATION
    11. 3.11 EVANGELISM
    12. 3.12 THE BENEFITS OF SPEED
  10. Chapter 4: Iterators
    1. 4.1 INTRODUCTION
    2. 4.2 HOMEMADE ITERATORS
    3. 4.3 EXAMPLES
    4. 4.4 FILTERS AND TRANSFORMS
    5. 4.5 THE SEMIPREDICATE PROBLEM
    6. 4.6 ALTERNATIVE INTERFACES TO ITERATORS
    7. 4.7 AN EXTENDED EXAMPLE: WEB SPIDERS
  11. Chapter 5: From Recursion to Iterators
    1. 5.1 THE PARTITION PROBLEM REVISITED
    2. 5.2 HOW TO CONVERT A RECURSIVE FUNCTION TO AN ITERATOR
    3. 5.3 A GENERIC SEARCH ITERATOR
    4. 5.4 OTHER GENERAL TECHNIQUES FOR ELIMINATING RECURSION
  12. Chapter 6: Infinite Streams
    1. 6.1 LINKED LISTS
    2. 6.2 LAZY LINKED LISTS
    3. 6.3 RECURSIVE STREAMS
    4. 6.4 THE HAMMING PROBLEM
    5. 6.5 REGEX STRING GENERATION
    6. 6.6 THE NEWTON-RAPHSON METHOD
    7. 6.7 POWER SERIES
  13. Chapter 7: Higher-Order Functions and Currying
    1. 7.1 CURRYING
    2. 7.2 COMMON HIGHER-ORDER FUNCTIONS
    3. 7.3 reduce() AND combine()
    4. 7.4 DATABASES
  14. Chapter 8: Parsing
    1. 8.1 LEXERS
    2. 8.2 PARSING IN GENERAL
    3. 8.3 RECURSIVE-DESCENT PARSERS
    4. 8.4 ARITHMETIC EXPRESSIONS
    5. 8.5 PARSING REGEXES
    6. 8.6 OUTLINES
    7. 8.7 DATABASE-QUERY PARSING
    8. 8.8 BACKTRACKING PARSERS
    9. 8.9 OVERLOADING
  15. Chapter 9: Declarative Programming
    1. 9.1 CONSTRAINT SYSTEMS
    2. 9.2 LOCAL PROPAGATION NETWORKS
    3. 9.3 LINEAR EQUATIONS
    4. 9.4 linogram: A DRAWING SYSTEM
    5. 9.5 CONCLUSION
  16. Index
  17. Function Index
  18. Instructions for online access