You are previewing Learning Perl, Second Edition.
O'Reilly logo
Learning Perl, Second Edition

Book Description

In this update of a bestseller, two leading Perl trainers teach you to use the most universal scripting language in the age of the World Wide Web. With a foreword by Larry Wall, the creator of Perl, this smooth, carefully paced book is the "official" guide for both formal (classroom) and informal learning. It is now current for Perl version 5.004. Learning Perl is a hands-on tutorial designed to get you writing useful Perl scripts as quickly as possible. Exercises (with complete solutions) accompany each chapter. A lengthy new chapter in this edition introduces you to CGI programming, while touching also on the use of library modules, references, and Perl's object-oriented constructs. Perl is a language for easily manipulating text, files, and processes. It comes standard on most UNIX platforms and is available free of charge on all other important operating systems. Perl technical support is informally available -- often within minutes -- from a pool of experts who monitor a USENET newsgroup (comp.lang.perl.misc) with tens of thousands of readers. Contents include:

  • A quick tutorial stroll through Perl basics

  • Systematic, topic-by-topic coverage of Perl's broad capabilities

  • Lots of brief code examples

  • Programming exercises for each topic, with fully worked-out answers

  • How to execute system commands from your Perl program

  • How to manage DBM databases using Perl

  • An introduction to CGI programming for the Web

Table of Contents

  1. Copyright
  2. Foreword
    1. Second Edition Update
  3. Preface
    1. What This Book Is About
    2. Retrieving Exercises
    3. Additional Resources
    4. How to Get Perl
    5. Conventions Used in This Book
    6. Support
    7. Acknowledgments for the First Edition
    8. Acknowledgments for the Second Edition
    9. We'd Like to Hear from You
  4. Introduction
    1. History of Perl
    2. Purpose of Perl
    3. Availability
    4. Basic Concepts
    5. A Stroll Through Perl
    6. Exercise
  5. Scalar Data
    1. What Is Scalar Data?
    2. Numbers
    3. Strings
    4. Scalar Operators
    5. Scalar Variables
    6. Scalar Operators and Functions
    7. <STDIN> as a Scalar Value
    8. Output with print
    9. The Undefined Value
    10. Exercises
  6. Arrays and List Data
    1. What Is a List or Array?
    2. Literal Representation
    3. Variables
    4. Array Operators and Functions
    5. Scalar and List Context
    6. <STDIN> as an Array
    7. Variable Interpolation of Arrays
    8. Exercises
  7. Control Structures
    1. Statement Blocks
    2. The if/unless Statement
    3. The while/until Statement
    4. The for Statement
    5. The foreach Statement
    6. Exercises
  8. Hashes
    1. What Is a Hash?
    2. Hash Variables
    3. Literal Representation of a Hash
    4. Hash Functions
    5. Hash Slices
    6. Exercises
  9. Basic I/O
    1. Input from STDIN
    2. Input from the Diamond Operator
    3. Output to STDOUT
    4. Exercises
  10. Regular Expressions
    1. Concepts About Regular Expressions
    2. Simple Uses of Regular Expressions
    3. Patterns
    4. More on the Matching Operator
    5. Substitutions
    6. The split and join Functions
    7. Exercises
  11. Functions
    1. Defining a User Function
    2. Invoking a User Function
    3. Return Values
    4. Arguments
    5. Private Variables in Functions
    6. Semiprivate Variables Using local
    7. File-Level my( ) Variables
    8. Exercises
  12. Miscellaneous Control Structures
    1. The last Statement
    2. The next Statement
    3. The redo Statement
    4. Labeled Blocks
    5. Expression Modifiers
    6. && and || as Control Structures
    7. Exercises
  13. Filehandles and File Tests
    1. What Is a Filehandle?
    2. Opening and Closing a Filehandle
    3. A Slight Diversion: die
    4. Using Filehandles
    5. The -x File Tests
    6. The stat and lstat Functions
    7. Exercises
  14. Formats
    1. What Is a Format?
    2. Defining a Format
    3. Invoking a Format
    4. More About the Fieldholders
    5. The Top-of-Page Format
    6. Changing Defaults for Formats
    7. Exercises
  15. Directory Access
    1. Moving Around the Directory Tree
    2. Globbing
    3. Directory Handles
    4. Opening and Closing a Directory Handle
    5. Reading a Directory Handle
    6. Exercises
  16. File and Directory Manipulation
    1. Removing a File
    2. Renaming a File
    3. Creating Alternate Names for a File: Linking
    4. Making and Removing Directories
    5. Modifying Permissions
    6. Modifying Ownership
    7. Modifying Timestamps
    8. Exercises
  17. Process Management
    1. Using system and exec
    2. Using Backquotes
    3. Using Processes as Filehandles
    4. Using fork
    5. Summary of Process Operations
    6. Sending and Receiving Signals
    7. Exercises
  18. Other Data Transformation
    1. Finding a Substring
    2. Extracting and Replacing a Substring
    3. Formatting Data with sprintf( )
    4. Advanced Sorting
    5. Transliteration
    6. Exercises
  19. System Database Access
    1. Getting Password and Group Information
    2. Packing and Unpacking Binary Data
    3. Getting Network Information
    4. Exercise
  20. User Database Manipulation
    1. DBM Databases and DBM Hashes
    2. Opening and Closing DBM Hashes
    3. Using a DBM Hash
    4. Fixed-Length Random Access Databases
    5. Variable-Length ( Text) Databases
    6. Exercises
  21. Converting Other Languages to Perl
    1. Converting awk Programs to Perl
    2. Converting sed Programs to Perl
    3. Converting Shell Programs to Perl
    4. Exercise
  22. CGI Programming
    1. The CGI.pm Module
    2. Your CGI Program in Context
    3. Simplest CGI Program
    4. Passing Parameters via CGI
    5. Less Typing
    6. Form Generation
    7. Other Form Elements
    8. Creating a Guestbook Program
    9. Troubleshooting CGI Programs
    10. Perl and the Web: Beyond CGI Programming
    11. Further Reading
    12. Exercises
  23. Exercise Answers
    1. Chapter 2
    2. Chapter 3
    3. Chapter 4
    4. Chapter 5
    5. Chapter 6
    6. Chapter 7
    7. Chapter 8
    8. Chapter 9
    9. Chapter 10
    10. Chapter 11
    11. Chapter 12
    12. Chapter 13
    13. Chapter 14
    14. Chapter 15
    15. Chapter 16
    16. Chapter 17
    17. Chapter 18
    18. Chapter 19
  24. Libraries and Modules
    1. Library Terminology
    2. Standard Modules
    3. CPAN: Beyond the Standard Library
  25. Networking Clients
    1. A Simple Client
    2. A Webget Client
    3. An Interactive Client
    4. Further Reading on Networking
  26. Topics We Didn't Mention
    1. Full Interprocess Communications
    2. The Debugger
    3. The Command Line
    4. Other Operators
    5. Many, Many More Functions
    6. Many, Many Predefined Variables
    7. Symbol Table Manipulation with *FRED
    8. Additional Regular-Expression Features
    9. Packages
    10. Embeddible, Extensible
    11. And Other Stuff
  27. Colophon
  28. Index