Table of Contents |
| Introduction | xxiii |
Part I | A Quick Start to Perl Programming | |
| 1 | Writing Your First Program | 3 |
| | | Introducing Perl 5 | 4 |
| | | | The Evolution of Perl | 4 |
| | | | A Perl Program | 6 |
| | | | Perl as an Interpreted Language | 7 |
| | | | Windows, Unix, and Perl | 9 |
| | | Running Perl Programs | 11 |
| | | | Using the MS-DOS Window | 11 |
| | | | Using the Unix Command Shell | 16 |
| | | Using Programmer's Editors | 20 |
| | | | Choosing a Windows Editor | 21 |
| | | | Choosing a Unix Editor | 23 |
| | | | Modifying a Program | 25 |
| | | Understanding Perl Syntax Basics | 27 |
| | | | Perl Program Structure | 27 |
| | | | Perl Program Components | 28 |
| | | Writing a CGI Program | 30 |
| | | | Defining CGI | 31 |
| | | | Understanding the Client/Server Interface Model | 32 |
| | | | Understanding HTTP Communications | 33 |
| | | | Configuring the Web Server | 36 |
| | | | Writing the Registration Form | 38 |
| | | | Creating the CGI Program | 41 |
| | | | Installing CGI Programs | 44 |
| | | | Understanding How a CGI Program Works | 45 |
| | | Summary | 50 |
| 2 | Debugging Your Programs | 53 |
| | | Handling Syntax Errors | 55 |
| | | | Pinpointing Syntax Errors | 55 |
| | | | Understanding Error Messages | 58 |
| | | Avoiding Errors | 63 |
| | | | Turning On Warning Messages | 63 |
| | | | Avoiding Misspelled Variable Names | 63 |
| | | | Following Good Coding Practices | 64 |
| | | | Testing Loop and Conditional Expressions | 65 |
| | | | Avoiding Common Perl 5 Mistakes | 67 |
| | | | Handling Runtime Errors | 70 |
| | | | Using the System Error Variable | 70 |
| | | | Inserting print Statements | 72 |
| | | | Searching for Bugs | 73 |
| | | Using a Debugger | 73 |
| | | | Running the Perl Debugger | 74 |
| | | | Debugging Using Emacs | 81 |
| | | | Running the ActiveState Windows Debugger | 83 |
| | | Debugging CGI Programs | 85 |
| | | | Running the Program with Test Data | 86 |
| | | | Adding print Statements | 87 |
| | | Summary | 89 |
Part II | Perl Programming Fundamentals | |
| 3 | Jump-Start on Programming Fundamentals | 95 |
| | | Jump-Start Definitions | 96 |
| | | Jump-Start Program | 100 |
| | | Operators and Context | 106 |
| | | Variables | 108 |
| | | | Variable Names | 109 |
| | | | Namespaces and Variable Declarations | 110 |
| | | | Scalar Variables | 111 |
| | | | Arrays | 113 |
| | | | Hashes | 115 |
| | | | References | 118 |
| | | Control Structures | 123 |
| | | | The if Family | 123 |
| | | | The SWITCH Construct | 125 |
| | | | The for Loop | 127 |
| | | | The foreach Loop | 128 |
| | | | The while and until Loops | 129 |
| | | What Next? | 130 |
| 4 | Operators and Programming Fundamentals | 133 |
| | | Perl 5 and Context | 134 |
| | | Numeric Operations | 135 |
| | | | Basic Numeric Operations | 135 |
| | | | The Assignment Operator | 137 |
| | | | Compound Assignment Operators | 138 |
| | | | Increment and Decrement Operators | 141 |
| | | Boolean Operations | 143 |
| | | String Operations | 147 |
| | | | String Comparisons | 150 |
| | | | ASCII Characters | 151 |
| | | Boolean Combination Operations | 155 |
| | | | The Logical AND Operator | 156 |
| | | | The Logical OR Operator | 158 |
| | | | The Logical NOT Operator | 158 |
| | | Binary Operations | 160 |
| | | | Binary Numbers | 160 |
| | | | Hexadecimal Numbers | 163 |
| | | | Binary Operators | 164 |
| | | Precedence and Associativity | 167 |
| | | Summary | 170 |
| 5 | Scalar Data | 173 |
| | | An Introduction to Scalar Variables | 174 |
| | | | What's a Scalar Variable? | 175 |
| | | | Scalar Variable Names | 176 |
| | | | What's a Literal? | 177 |
| | | Strings and Character Data | 177 |
| | | | Quotation Marks | 178 |
| | | | The Quote Operators | 184 |
| | | | Rules for String Literals | 187 |
| | | Numeric Literals | 187 |
| | | | Numeric Formats | 189 |
| | | | Fixed-Point Number Solutions | 189 |
| | | Boolean Values | 195 |
| | | Variable Declarations | 196 |
| | | | Variables and Namespaces | 197 |
| | | | The my and local Keywords | 198 |
| | | | The Case against Recycled Variables | 199 |
| | | Scalar Context versus List Context | 199 |
| | | Summary | 203 |
| 6 | Arrays and Hashes | 205 |
| | | An Introduction to Arrays | 206 |
| | | Array Data Storage and Retrieval | 208 |
| | | | Array Cell Assignment | 208 |
| | | | Array List Assignment | 211 |
| | | | Array Sizing | 213 |
| | | | Array Data Retrieval | 217 |
| | | | Array Slices | 218 |
| | | Built-In Functions for Working with Arrays | 222 |
| | | | Stack and Queue Functions | 222 |
| | | | List Modification with the splice Function | 227 |
| | | | Array Sorting Functions | 228 |
| | | An Introduction to Hashes | 230 |
| | | Hash Data Storage and Retrieval | 231 |
| | | | Hash Keys | 232 |
| | | | Hash Value Retrieval | 235 |
| | | Built-In Functions for Working with Hashes | 236 |
| | | | Key Retrieval Functions | 236 |
| | | | Item Removal with the delete Function | 241 |
| | | | Item Verification with the exists Function | 241 |
| | | Summary | 241 |
| 7 | References | 245 |
| | | An Introduction to References | 246 |
| | | | Reference Operators | 248 |
| | | | Types of Reference Variables | 248 |
| | | Direct References and Dereferencing | 251 |
| | | | Direct Scalar References | 252 |
| | | | Direct Array References | 254 |
| | | | Direct Hash References | 257 |
| | | | A Quick Recap | 257 |
| | | Dereferencing Alternatives | 258 |
| | | | Curly Braces | 258 |
| | | | The Right Arrow Operator | 259 |
| | | | Square Brackets | 259 |
| | | Multi-Dimensional Arrays | 260 |
| | | Three-Dimensional Array Dereferencing | 264 |
| | | | The Last Cell Index for Loop Control | 264 |
| | | | Multi-Dimensional Arrays as Indexes | 265 |
| | | Anonymous Arrays and Hashes | 266 |
| | | Summary | 269 |
| 8 | Conditional Statements | 271 |
| | | An Introduction to Branching Statements | 272 |
| | | | Simple Conditional Expressions | 273 |
| | | | Blocks of Statements | 274 |
| | | | Complex Conditional Expressions | 275 |
| | | Good Coding Practices | 276 |
| | | | Commenting Your Code | 276 |
| | | | Indenting | 278 |
| | | | Using Variable Names as Array Indexes | 279 |
| | | The if Family | 281 |
| | | | if else Statements | 282 |
| | | | if elsif else Statements | 284 |
| | | | Nested if Clauses versus elsif Clauses | 286 |
| | | Switch Simulation | 293 |
| | | | Labels | 299 |
| | | | The split Function | 300 |
| | | | if Blocks versus Simulated switch Statements | 301 |
| | | The Ternary Operator | 305 |
| | | Summary | 306 |
| 9 | Loops | 309 |
| | | An Introduction to Loops | 310 |
| | | while/until Loops and do Statements | 312 |
| | | | while Loops | 312 |
| | | | until Loops | 316 |
| | | | The do Statement | 317 |
| | | The for and foreach Loops | 322 |
| | | | for Loops | 322 |
| | | | foreach loops | 326 |
| | | | Array References in Loops | 339 |
| | | Loop Modifiers | 343 |
| | | | The continue Block | 343 |
| | | | The last Command | 344 |
| | | | next | 345 |
| | | | The redo Command | 346 |
| | | Summary | 347 |
Part III | Input and Output Handling | |
| 10 | Jump-Start on Input/Output | 351 |
| | | Jump-Start Definitions | 352 |
| | | Jump-Start Program | 354 |
| | | Command-Line Input | 356 |
| | | File Input | 358 |
| | | | Opening a File | 358 |
| | | | Reading from a File | 360 |
| | | File Output | 362 |
| | | | Outputting Program Data | 362 |
| | | | Setting and Closing File Handles | 363 |
| | | | Formatting Output Data | 364 |
| | | Directories | 365 |
| | | | Reading a Directory | 365 |
| | | | Creating, Deleting, and Changing Directories | 366 |
| | | File and Directory Modules | 367 |
| | | What Next? | 368 |
| 11 | Input and Output Basics | 371 |
| | | Command-Line Input | 372 |
| | | | Command-Line Arguments | 373 |
| | | | Command-Line Switches | 381 |
| | | Opening Files | 388 |
| | | | Parts of a Filename | 388 |
| | | | File Handles | 390 |
| | | | The open Function | 391 |
| | | Moving through Files | 393 |
| | | Positioning with the seek Function | 394 |
| | | | Reading the File into an Array | 396 |
| | | Modifying Files | 397 |
| | | | Using the Hard Disk as Workspace | 399 |
| | | | Using Memory as Workspace | 401 |
| | | | Closing Files | 403 |
| | | | Appending Data | 403 |
| | | | Deleting a File | 403 |
| | | Using File Test Operators | 405 |
| | | | File Privileges Tests | 410 |
| | | | File Type Tests | 412 |
| | | | File Existence and Size Tests | 413 |
| | | | File Modification Tests | 413 |
| | | | Unix File Handle Type Tests | 414 |
| | | Summary | 414 |
| 12 | Printing and Formatting Techniques | 417 |
| | | Using the print Function | 418 |
| | | | Setting the Default File Handle | 419 |
| | | | Using the Heredoc Operator | 420 |
| | | Using Print Formatting Functions | 423 |
| | | | Formatting with printf and sprintf | 423 |
| | | | Using Print Escape Sequences | 429 |
| | | | Printing Arrays | 430 |
| | | Writing Formatted Output | 432 |
| | | | Naming Formats | 435 |
| | | | Defining Format Output | 435 |
| | | | Formatting with Special Variables | 437 |
| | | | Handling Long Data Items | 439 |
| | | Summary | 442 |
| 13 | Directories and System I/O Utilities | 445 |
| | | Directory Modules and Functions | 446 |
| | | | Working with Directories | 448 |
| | | | Working with Directory Handles | 452 |
| | | File Functions | 456 |
| | | | Opening a File | 457 |
| | | | Reading and Writing to a File | 458 |
| | | | Getting and Setting File Information | 460 |
| | | | Using Unix-Only Functions | 469 |
| | | File Modules | 470 |
| | | | Platform-Independent File Symbols | 472 |
| | | | Platform-Independent Copying and Moving | 473 |
| | | | I/O Interfaces | 474 |
| | | | A File System Operations Interface | 479 |
| | | Summary | 479 |
Part IV | Data Manipulation | |
| 14 | Jump-Start on String Functions and Regular Expressions | 485 |
| | | Jump-Start Definitions | 486 |
| | | Jump-Start Program | 488 |
| | | String Functions | 490 |
| | | | The length Function | 492 |
| | | | The split Function | 492 |
| | | | The translate Function | 493 |
| | | | The substitute Function | 493 |
| | | | The index Function | 494 |
| | | | The substr Function | 494 |
| | | | Character-Case Functions | 494 |
| | | Regular Expressions | 495 |
| | | | The Pattern-Match Function | 496 |
| | | | Elements of Regular Expressions | 496 |
| | | | A Regular Expression Example | 499 |
| | | What Next? | 502 |
| 15 | String Manipulation | 505 |
| | | Working with String Parts | 506 |
| | | | Getting the First and Last Position of a Substring | 506 |
| | | | Extracting Substrings | 508 |
| | | | Getting the String's Length | 509 |
| | | | Replacing Strings | 511 |
| | | Changing Characters | 513 |
| | | | Translating between Numbers and Characters | 513 |
| | | | Changing Case | 518 |
| | | | Translating Single Characters | 521 |
| | | | Removing End-of-Line Characters | 522 |
| | | Separating and Joining Strings | 524 |
| | | | Splitting Strings | 524 |
| | | | Joining Strings Together | 529 |
| | | Packing Characters | 530 |
| | | Creating Sorting Subroutines | 534 |
| | | | Using Comparison Operators | 535 |
| | | | Sorting a Hash by Value | 537 |
| | | | Sorting under Multiple Conditions | 538 |
| | | Summary | 542 |
| 16 | Regular Expressions | 545 |
| | | An Introduction to Regular Expressions | 546 |
| | | | The Functions for Matching Patterns | 546 |
| | | | Matches in Conditional Expressions | 548 |
| | | Regular Expression Components | 549 |
| | | | Meta-Characters | 550 |
| | | | Atoms | 551 |
| | | | Rules for Building Regular Expressions | 552 |
| | | | Pattern-Match Variables | 565 |
| | | Pattern Modifiers | 568 |
| | | | Global Matches | 568 |
| | | | Ignore Case Matches | 569 |
| | | | Multiple and Single Line Matches | 570 |
| | | | Only Once Please | 571 |
| | | | Extra Spaces and Comments | 572 |
| | | Regular Expression Examples | 573 |
| | | | A Simple Pattern | 573 |
| | | | A Whole Word Match | 574 |
| | | | Electronic Commerce Patterns | 576 |
| | | | A Globally Lazy Match | 581 |
| | | Summary | 584 |
Part V | Advanced Perl Programming | |
| 17 | Jump-Start on Advanced Programming Concepts | 589 |
| | | Jump-Start Definitions | 590 |
| | | Jump-Start Program | 594 |
| | | Packages | 598 |
| | | | Package Namespaces | 598 |
| | | | Qualified and Unqualified Names | 599 |
| | | Data Scope | 600 |
| | | | Global Scope | 601 |
| | | | Dynamic Scope | 602 |
| | | | Lexical Scope | 602 |
| | | Subroutines | 603 |
| | | | Subroutine Calls | 603 |
| | | | Subroutine Parameters | 604 |
| | | | Subroutine Return Values | 606 |
| | | Object-Oriented Perl 5 | 606 |
| | | | Object Methods | 607 |
| | | | Object Variables | 609 |
| | | | Inheritance | 610 |
| | | E-Mail Transfer | 611 |
| | | What Next? | 613 |
| 8 | Functional Programming | 615 |
| | | Packages | 616 |
| | | | Package Definition | 617 |
| | | | Symbol Tables | 622 |
| | | Data Scope | 628 |
| | | | Global Scope | 629 |
| | | | Dynamic Scope | 630 |
| | | | Lexical Scope | 632 |
| | | Subroutines and Functions | 636 |
| | | | Subroutine Definition | 636 |
| | | | Subroutine Calling Syntax | 637 |
| | | | Subroutine Parameter Lists | 639 |
| | | | Returning Data | 643 |
| | | Summary | 645 |
| 19 | Object-Oriented Programming | 649 |
| | | An Introduction to Objects and Classes | 650 |
| | | | Object Characteristics | 650 |
| | | | Object Classes | 651 |
| | | Object Methods | 651 |
| | | | Class Methods | 652 |
| | | | Constructors | 652 |
| | | | Object Reference Variables | 654 |
| | | | Instance Methods | 658 |
| | | Object Variables | 662 |
| | | | Instance Variables | 663 |
| | | | Class Variables | 668 |
| | | | Destructors | 669 |
| | | Named Parameters | 671 |
| | | Inheritance | 675 |
| | | Summary | 681 |
| 20 | E-Mail Solutions | 685 |
| | | An Introduction to E-Mail Programs and Protocols | 686 |
| | | | The sendmail Program | 687 |
| | | | SMTP Servers | 688 |
| | | Unix E-Mail Solutions | 691 |
| | | | A Registration Application | 691 |
| | | | A Mailing List Application | 699 |
| | | Windows E-Mail Solutions | 702 |
| | | | Blat: A Windows E-Mail Program | 703 |
| | | | Sender.pm: A Perl E-Mail Interface | 708 |
| | | Summary | 724 |
Part VI | Windows Only | |
| 21 | Jump-Start on Windows Solutions | 729 |
| | | Jump-Start Definitions | 730 |
| | | Jump-Start Program | 732 |
| | | Windows System Information | 739 |
| | | | Drive Information | 739 |
| | | | File System Information | 740 |
| | | | User Information | 741 |
| | | | Network Information | 743 |
| | | Registry Information | 745 |
| | | | Event Log Information | 747 |
| | | Perl and Your Windows Database | 749 |
| | | | The Database Interface | 750 |
| | | | SQL Statements | 752 |
| | | What Next? | 754 |
| 22 | Win32 System Administration | 757 |
| | | Win32 Extensions | 758 |
| | | The Disk Drive | 762 |
| | | | Getting the Drives | 762 |
| | | | Getting the Disk Configuration | 764 |
| | | The File System | 768 |
| | | User Information | 773 |
| | | | Getting Login Information | 773 |
| | | | Getting User Details | 775 |
| | | Network Administration | 780 |
| | | | Building a Network Diagnostic Utilities Interface | 780 |
| | | | Managing Physical Addresses | 786 |
| | | | Configuring TCP/IP | 787 |
| | | | Getting NetBIOS Statistics | 789 |
| | | | Using PING | 791 |
| | | | Getting Network Routing Tables | 793 |
| | | | Tracing Internet Routes | 795 |
| | | DLL Functions | 797 |
| | | Summary | 800 |
| 23 | The Registry and Event Log | 803 |
| | | An Introduction to the Registry | 804 |
| | | | Running the Registry Editor | 804 |
| | | | Backing Up Your Registry | 806 |
| | | Registry Manipulation | 807 |
| | | | Reading the Registry | 807 |
| | | | Creating a Registry Key | 812 |
| | | | Deleting Registry Keys | 814 |
| | | | Getting Registry Data | 816 |
| | | | Modifying Registry Data | 819 |
| | | An Introduction to the Event Log | 821 |
| | | Event Log Manipulation | 823 |
| | | | Reading the Event Log | 824 |
| | | | Writing to the Event Log | 831 |
| | | | Using Other EventLog Methods | 833 |
| | | | Extending the EventLog Class | 835 |
| | | Summary | 841 |
| 24 | Databases and the Web | 843 |
| | | An Introduction to Databases | 844 |
| | | The ODBC Connection | 845 |
| | | | Creating a DSN | 846 |
| | | | The Win32::ODBC Module | 853 |
| | | Existing Data | 858 |
| | | | Creating a Database Table | 858 |
| | | | Importing Text Data | 860 |
| | | SQL--The Database Language | 863 |
| | | | Creating a Table | 865 |
| | | | Modifying a Table | 868 |
| | | | Inserting Data into a Table | 869 |
| | | | Deleting Data from a Table | 870 |
| | | | Updating Data in a Table | 872 |
| | | | Selecting Data from a Table | 872 |
| | | Your Database and the Internet | 873 |
| | | | Setting Up for Access and the Web | 874 |
| | | | Initializing the Transportation Database | 876 |
| | | | Importing Data into the Transportation Database | 880 |
| | | | Searching for Cars on the Web | 885 |
| | | | Displaying the Online Search Results | 888 |
| | | Summary | 894 |
| Index | 895 |