Programming Perl第三版英文原&ccedil

Programming Perl第三版英文原ç

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Programming Perl Programming Perl Third Edition Larry Wall, Tom Christiansen & Jon Orwant Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo Programming Perl, Third Edition by Larry Wall, Tom Christiansen, and Jon Orwant Copyright © 2000, 1996, 1991 O’Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA 95472. Editor, First Edition: Tim O’Reilly Editor, Second Edition: Steve Talbott Editor, Third Edition: Linda Mui Technical Editor: Nathan Torkington Production Editor: Melanie Wang Cover Designer: Edie Freedman Printing History: January 1991: First Edition. September 1996: Second Edition. July 2000: Third Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of a camel and the Perl language is a trademark of O’Reilly & Associates, Inc. Permission may be granted for non-commercial use; please inquire by sending mail to [email protected] While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Library of Congress Cataloging-in-Publication Data Wall, Larry. Programming Perl/Larry Wall, Tom Christiansen & Jon Orwant.--3rd ed. p. cm. ISBN 0-596-00027-8 1. Perl (Computer program language) I. Christiansen, Tom. II. Orwant, Jon. III. Title. QA76.73.P22 W35 2000 005.13'3--dc21 ISBN: 0-596-00027-8 [M] 00-055799 Table of Contents Preface ................................................................................................................. xvii I: Overview .................................................................................................. 1 1: An Overview of Perl .................................................................................... 3 Getting Started .................................................................................................... 3 Natural and Artificial Languages ........................................................................ 4 An Average Example ........................................................................................ 17 Filehandles ........................................................................................................ 20 Operators .......................................................................................................... 22 Control Structures ............................................................................................. 29 Regular Expressions ......................................................................................... 35 List Processing .................................................................................................. 41 What You Don’t Know Won’t Hurt You (Much) ............................................. 43 II : The Gory Details ........................................................................... 45 2: Bits and Pieces ........................................................................................... 47 Atoms ................................................................................................................ Molecules .......................................................................................................... Built-in Data Types ........................................................................................... Variables ............................................................................................................ Names ............................................................................................................... Scalar Values ..................................................................................................... Context .............................................................................................................. 47 49 50 52 53 58 69 v vi Table of Contents List Values and Arrays ...................................................................................... Hashes ............................................................................................................... Typeglobs and Filehandles .............................................................................. Input Operators ................................................................................................ 72 76 78 79 3: Unary and Binary Operators .............................................................. 86 Terms and List Operators (Leftward) .............................................................. 89 The Arrow Operator ......................................................................................... 90 Autoincrement and Autodecrement ................................................................ 91 Exponentiation ................................................................................................. 92 Ideographic Unary Operators .......................................................................... 92 Binding Operators ............................................................................................ 93 Multiplicative Operators ................................................................................... 94 Additive Operators ........................................................................................... 95 Shift Operators .................................................................................................. 95 Named Unary and File Test Operators ............................................................ 95 Relational Operators ....................................................................................... 100 Equality Operators ......................................................................................... 101 Bitwise Operators ........................................................................................... 101 C-Style Logical (Short-Circuit) Operators ...................................................... 102 Range Operator .............................................................................................. 103 Conditional Operator ..................................................................................... 105 Assignment Operators .................................................................................... 107 Comma Operators .......................................................................................... 108 List Operators (Rightward) ............................................................................. 109 Logical and, or, not, and xor ......................................................................... 109 C Operators Missing from Perl ...................................................................... 110 4: Statements and Declarations ............................................................ 111 Simple Statements .......................................................................................... Compound Statements ................................................................................... if and unless Statements ................................................................................ Loop Statements ............................................................................................. Bare Blocks ..................................................................................................... goto ................................................................................................................. Global Declarations ........................................................................................ Scoped Declarations ....................................................................................... Pragmas ........................................................................................................... 111 113 114 115 123 126 127 129 136 Table of Contents vii 5: Pattern Matching .................................................................................... 139 The Regular Expression Bestiary ................................................................... Pattern-Matching Operators ........................................................................... Metacharacters and Metasymbols .................................................................. Character Classes ............................................................................................ Quantifiers ...................................................................................................... Positions .......................................................................................................... Capturing and Clustering ............................................................................... Alternation ...................................................................................................... Staying in Control ........................................................................................... Fancy Patterns ................................................................................................ 140 143 158 165 176 178 182 187 188 202 6: Subroutines ............................................................................................... 217 Syntax .............................................................................................................. Semantics ........................................................................................................ Passing References ......................................................................................... Prototypes ....................................................................................................... Subroutine Attributes ..................................................................................... 217 219 224 225 231 7: Formats ...................................................................................................... 234 Format Variables ............................................................................................. 237 Footers ............................................................................................................ 240 8: References .................................................................................................. 242 What Is a Reference? ...................................................................................... Creating References ........................................................................................ Using Hard References ................................................................................... Symbolic References ...................................................................................... Braces, Brackets, and Quoting ...................................................................... 242 245 251 263 264 9: Data Structures ....................................................................................... 268 Arrays of Arrays .............................................................................................. Hashes of Arrays ............................................................................................ Arrays of Hashes ............................................................................................ Hashes of Hashes ........................................................................................... Hashes of Functions ....................................................................................... More Elaborate Records ................................................................................. Saving Data Structures ................................................................................... 268 275 277 279 282 283 286 viii Table of Contents 10: Packages ..................................................................................................... 288 Symbol Tables ................................................................................................ 293 Autoloading .................................................................................................... 296 11: Modules ...................................................................................................... 299 Using Modules ................................................................................................ 299 Creating Modules ........................................................................................... 301 Overriding Built-in Functions ........................................................................ 306 12: Objects ......................................................................................................... 308 Brief Refresher on Object-Oriented Lingo .................................................... Perl’s Object System ....................................................................................... Method Invocation ......................................................................................... Object Construction ....................................................................................... Class Inheritance ............................................................................................ Instance Destructors ....................................................................................... Managing Instance Data ................................................................................. Managing Class Data ...................................................................................... Summary ......................................................................................................... 308 310 311 317 321 330 331 343 346 13: Overloading .............................................................................................. 347 The overload Pragma ..................................................................................... Overload Handlers ......................................................................................... Overloadable Operators ................................................................................. The Copy Constructor (=) .............................................................................. When an Overload Handler Is Missing (nomethod and fallback) .............. Overloading Constants ................................................................................... Public Overload Functions ............................................................................ Inheritance and Overloading ......................................................................... Run-Time Overloading ................................................................................... Overloading Diagnostics ................................................................................ 348 349 350 357 358 359 360 361 361 362 14: Tied Variables .......................................................................................... 363 Tying Scalars ................................................................................................... Tying Arrays ................................................................................................... Tying Hashes .................................................................................................. Tying Filehandles ........................................................................................... A Subtle Untying Trap .................................................................................... Tie Modules on CPAN .................................................................................... 365 372 378 384 395 397 Table of Contents III :Perl as Technology ix .................................................................... 399 15: Unicode ...................................................................................................... 401 Building Character .......................................................................................... 402 Effects of Character Semantics ....................................................................... 405 Caution, Working ...................................................................................... 409 16: Interprocess Communication ............................................................ 411 Signals ............................................................................................................. Files ................................................................................................................. Pipes ................................................................................................................ System V IPC .................................................................................................. Sockets ............................................................................................................ 412 418 426 434 437 17: Threads ....................................................................................................... 446 The Process Model ......................................................................................... 447 The Thread Model .......................................................................................... 448 18: Compiling .................................................................................................. 464 The Life Cycle of a Perl Program .................................................................. Compiling Your Code .................................................................................... Executing Your Code ..................................................................................... Compiler Backends ........................................................................................ Code Generators ............................................................................................ Code Development Tools .............................................................................. Avant-Garde Compiler, Retro Interpreter ...................................................... 465 467 473 476 477 479 480 19: The Command-Line Interface ............................................................ 486 Command Processing ..................................................................................... 486 Environment Variables ................................................................................... 503 20: The Perl Debugger .................................................................................. 506 Using the Debugger ....................................................................................... Debugger Commands .................................................................................... Debugger Customization ............................................................................... Unattended Execution .................................................................................... Debugger Support .......................................................................................... The Perl Profiler ............................................................................................. 507 509 518 521 523 525 x Table of Contents 21: Internals and Externals ....................................................................... 530 How Perl Works ............................................................................................. Internal D...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern