Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 700 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
700
Dung lượng
3,2 MB
Nội dung
Perl 5
by Example
by David Medinets
C O N T E N T S
Chapter 1 Getting Your Feet Wet
Origins●
Similar to C?●
Cost and Licensing●
Do You Have Perl Installed?●
Getting and Installing Perl●
Your First Perl Program
Creating the Program❍
Invocation❍
●
Comments in Your Program●
Summary●
Review Questions●
Review Exercises●
Chapter 2 Numeric and String Literals
Numeric Literals
Example: Numbers❍
●
Add this book to your Personal
Bookshelf
Return to your Personal Bookshelf
PERL 5BY EXAMPLE
By Group Que
ISBN: 0789708663
Published: 03-Oct-1996
Retail Price: $40 US
Buy this Book
This will open in a new
browser window.
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (1 of 28) [29/06/1999 12:11:02]
String Literals
Example: Single-Quoted Strings❍
Example: Double-Quoted Strings❍
Example: Back-Quoted Strings❍
●
Array Literals
Example: Printing an Array❍
Example: Nesting Arrays❍
Example: Using a Range of Values❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 3 Variables
Scalar Variables
Example: Assigning Values to Scalar Variables❍
Changing Values in Scalar Variables❍
●
Array Variables
Example: Assigning Values to Array Variables❍
Example: Using Array Elements❍
Example: Using Negative Subscripts❍
Example: Determining the Number of Elements in an Array❍
Example: How to Grab a Slice (or Part) of an Array❍
●
Associative Array Variables
Example: Assigning Values to Associative Array Variables❍
●
Double-Quoted Strings Revisited
Example: Variable Interpolation❍
Example: Using the $" Special Variable❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 4 Operators
Operator Types●
The Binary Arithmetic Operators●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (2 of 28) [29/06/1999 12:11:02]
Example: The Exponentiation Operator❍
Example: The Modulus Operator❍
The Unary Arithmetic Operators
Example: The Pre-increment Operator❍
Example: The Pre-decrement Operator❍
Example: The Post-increment Operator❍
●
The Logical Operators
Example: The "AND" Operator (&&)❍
Example: The "OR" Operator (||)❍
●
Example: The "NOT" Operator (!)●
The Bitwise Operators
Example: Using the &, |, and ^ Operators❍
Example: Using the >> and << Operators❍
●
The Numeric Relational Operators
Example: Using the <=> Operator❍
●
The String Relational Operators
Example: Using the cmp Operator❍
●
The Ternary Operator
Example: Using the Ternary Operator to Assign Values❍
●
The Range Operator ( )
Example: Using the Range Operator❍
●
The String Operators (. and x)
Example: Using the Concatenation Operator❍
Example: Using the Repetition Operator❍
●
The Assignment Operators
Example: Assignment Using Array Slices❍
Example: Assigning an Array to Scalar Variables❍
●
Order of Precedence
Example: Order of Precedence❍
●
Summary●
Review Questions●
Review Exercises●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (3 of 28) [29/06/1999 12:11:02]
Chapter 5 Functions
Example: Using the Parameter Array (@_)❍
Example: Passing Parameters by Reference❍
Example: Scope of Variables❍
Example: Using a List as a Function Parameter❍
Example: Nesting Function Calls❍
Example: Using a Private Function❍
String Functions
Example: Changing a String's Value❍
Example: Searching a String❍
●
Array Functions
Example: Printing an Associative Array❍
Example: Checking the Existence of an Element❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 6 Statements
Understanding Expressions●
Statement Blocks●
Statement Blocks and Local Variables●
Statement Types
Example: Using the if Modifier❍
Example: Using the unless Modifier❍
Example: Using the until Modifier❍
Example: Using the while Modifier❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 7 Control Statements
Decision Statements
Example: The if Statement❍
●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (4 of 28) [29/06/1999 12:11:02]
Loop Statements
Example: While Loops❍
Example: Until Loops❍
Example: For Loops❍
Example: Foreach Loops❍
●
Jump Keywords
Example: The last Keyword❍
Example: The next Keyword❍
Example: The redo Keyword❍
Example: The goto Keyword❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 8 References
Reference Types
Example: Passing Parameters to Functions❍
Example: The ref() Function❍
Example: Creating a Data Record❍
Example: Interpolating Functions Inside Double-Quoted Strings❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 9 Using Files
Some Files Are Standard
Example: Using STDIN❍
Example: Using Redirection to Change STDIN and STDOUT❍
Example: Using the Diamond Operator (<>)❍
●
File Test Operators
Example: Using File Tests❍
●
File Functions
Example: Opening Files❍
Example: Binary Files❍
●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (5 of 28) [29/06/1999 12:11:02]
Example: Getting File Statistics❍
Example: Using the Directory Functions❍
Example: Printing Revisited❍
Globbing
Example: Assigning a Glob to an Array❍
●
Using Data Structures with Files
Example: Splitting a Record into Fields❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 10 Regular Expressions
Pattern Delimiters●
The Matching Operator (m//)
The Matching Options❍
●
The Substitution Operator (s///)
The Substitution Options❍
●
The Translation Operator (tr///)
The Translation Options❍
●
The Binding Operators (=~ and !~)●
How to Create Patterns
Example: Character Classes❍
Example: Quantifiers❍
Example: Pattern Memory❍
Example: Pattern Precedence❍
Example: Extension Syntax❍
●
Pattern Examples
Example: Using the Match Operator❍
Example: Using the Substitution Operator❍
Example: Using the Translation Operator❍
Example: Using the Split() Function❍
●
Summary●
Review Questions●
Review Exercises●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (6 of 28) [29/06/1999 12:11:02]
Chapter 11 Creating Reports
What's a Format Statement?
Example: Using Field Lines❍
Example: Report Headings❍
Example: Using Functions in the Value Line❍
Example: Changing Formats❍
Example: Using Long Pieces of Text in Reports❍
Example: Writing to a File Instead of STDOUT❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 12 Using Special Variables
What Are the Special Variables?
Example: Using the DATA File Handle❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 13 Handling Errors and Signals
Checking for Errors●
Example: Using the errno Variable
Example: Using the or Logical Operator❍
Example: Using the die() Function❍
Example: Using the warn() Function❍
●
Trapping Fatal Errors
Example: Using the eval() Function❍
●
What Is a Signal?
Example: How to Handle a Signal❍
●
Summary●
Review Questions●
Review Exercises●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (7 of 28) [29/06/1999 12:11:02]
Chapter 14 What Are Objects?
Learning about Classes●
Abstract Thinking●
Overriding Methods with Polymorphism●
Keeping Code and Data Together with Encapsulation●
How Perl Handles Objects
Example: Bless the Hash and Pass the Reference❍
Example: Initializing Properties❍
Example: Using Named Parameters in Constructors❍
Example: Inheritance, Perl Style❍
Example: Polymorphism❍
Example: How One Class Can Contain Another❍
●
Static Versus Regular Methods and Variables●
Summary●
Review Questions●
Review Exercises●
Chapter 15 Perl Modules
Module Constructors and Destructors
The BEGIN Block❍
The END Block❍
●
Symbol Tables●
The require Compiler Directive●
The use Compiler Directive●
What's a Pragma?●
The strict Pragma●
The Standard Modules●
strict, my() and Modules●
Module Examples
Example: The Carp Module❍
Example: The English Module❍
Example: The Env Module❍
●
Summary●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (8 of 28) [29/06/1999 12:11:02]
Review Questions●
Review Exercises●
Chapter 16 Debugging Perl
Syntax Errors●
Common Syntax Errors●
Logic Errors
Using the -w Command-Line Option❍
Being Strict with Your Variables❍
Stepping Through Your Script❍
Examples: Displaying Information❍
Examples: Using the n Command❍
Examples: Using Breakpoints❍
Examples: Creating Command Aliases❍
Examples: Using the Debugger as an Interactive Interpreter❍
●
Summary●
Review Questions●
Review Exercises●
Chapter 17 Using Command-Line
Options
How Are the Options Specified?●
What Are the Options?
Example: Using the -0 Option❍
Example: Using the -n and -p Options❍
Example: Using the -i Option❍
Example: Using the -s Option❍
●
Summary●
Review Questions●
Review Exercises●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (9 of 28) [29/06/1999 12:11:02]
Chapter 18 Using Internet Protocols
Sockets
The Server Side of a Conversation❍
The Client Side of a Conversation❍
●
Using the Time Service●
Sending Mail (SMTP)
The MAIL Command❍
The RCPT Command❍
The DATA Command❍
Reporting Undeliverable Mail❍
Using Perl to Send Mail❍
●
Receiving Mail (POP)●
Checking for Upness (Echo)●
Transferring Files (FTP)●
Reading the News (NNTP)●
The World Wide Web (HTTP)●
Summary●
Review Questions●
Review Exercises●
Chapter 19 What Is CGI?
Why Use Perl for CGI?●
CGI Apps versus Java Applets●
Should You Use CGI Modules?●
How Does CGI Work?●
Calling Your CGI Program●
Your First CGI Program●
Why Are File Permissions Important in UNIX?●
HTTP Headers●
CGI and Environment Variables●
URL Encoding●
Security●
CGIwrap and Security●
Reading a fine mcp.com book byQuePERL5BY EXAMPLE
http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (10 of 28) [29/06/1999 12:11:03]
[...]... 12:11:03] Reading a fine mcp.com book byQuePERL5BYEXAMPLE violation of United States copyright laws For information, address Que Corporation, 201 W 103rd Street, Indianapolis, IN 46290 You may reach Que' s direct sales line by calling 1-8 0 0-4 28 -5 3 31 ISBN: 0-7 89 7-0 86 6-3 HTML conversion by : M/s LeafWriters (India) Pvt Ltd Website : http://leaf.stpn.soft.net e-mail : leafwriters@leaf.stpn.soft.net... 12:11:03] Reading a fine mcp.com book byQuePERL5BYEXAMPLE Programming is the same way You must actually run some programs in order to really understand the concepts Perl5ByExample will teach you how to use the Perl programming language by showing examples that demonstrate the concepts being discussed The examples are designed to give you a chance to experiment-which in turn should clarify the... mcp.com book byQuePERL5BYEXAMPLE r getc ([FILEHANDLE]) r getgrent ( ) r getgrgid (GID) r getgrname (NAME) r gethostbyaddr (ADDRESS, AF_INIT) r gethostbyname (NAME, [PROTOCOL]) r gethostent ( ) r getlogin ( ) r getnetbyaddr (ADDRESS, ADDR_TYPE) r getnetbyname (NAME) r getnetent ( ) r getpeername (SOCKET) r getpgrp (PID) r getppid ( ) r getpriority (WHICH, WHO) r getprotobyname (NAME) r getprotobynumber... Reading a fine mcp.com book byQuePERL5 BY EXAMPLE Appendix A Answers to Review Questions Appendix B Glossary q Abstraction q Alternation q Alternative Quotes q Anchor q Anonymous Functions and Variables q ANSI q Argument q Array q Array Context q Array Range q Array Slice q Array Splice q ASCII q Assignment q Associative Array q Associativity (left-to-right & right-to-left) q awk q Backtracking... and !~) q How to Create Patterns r r Example: Quantifiers r Example: Pattern Memory r Example: Pattern Precedence r q Example: Character Classes Example: Extension Syntax Pattern Examples r Example: Using the Match Operator r Example: Using the Substitution Operator r Example: Using the Translation Operator r Example: Using the Split() Function q Summary q Review Questions q Review Exercises You can... Internet-such as FTP, SMTP, and POP Chapter 19, "What Is CGI?," eases you into writing scripts that can be executed by remote users Chapter 20, "Form Processing," discusses HTML forms and how http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (27 of 28) [29/06/1999 12:11:03] Reading a fine mcp.com book byQuePERL5 BY EXAMPLE Perl scripts can process form information Chapter 21, "Using Perl with... Backtracking q Binary Mode q Bitwise Operations q Block q Call by Reference q Call by Value q Character Classes q Child Process q Class q Client/Server q Command-Line Options q Compiler http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html (13 of 28) [29/06/1999 12:11:03] Reading a fine mcp.com book byQuePERL5 BY EXAMPLE q Compile-Time Error q Concatenation q Constant q Constructor q Context... return to them frequently After you've gone through several chapters, you'll begin to understand more often the reason why a concept was illustrated or a question was asked Returning to questions that frustrated you earlier and realizing that now you know the answers can be a big confidence builder Who Should Use This Book? Perl5 By Example should be read by anyone seeking to learn Perl If you don't... it http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html ( 25 of 28) [29/06/1999 12:11:03] Reading a fine mcp.com book byQuePERL5 BY EXAMPLE You can use the examples in this book with just about any hardware and operating system I'm not sure that they would work on an Amiga system but other than that you should be able to run every example How to Use This Book There are several ways to use this... Inter-process Communication q I/O q IPC q Key-Value Pair q Label q LF q Library q List q Literal q Loop q Meta Characters q Module q Namespace q Object q Octal q Operator q Parameter q Polymorphism q Port q Precedence q Procedure q Protocol q Range q Record http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html ( 15 of 28) [29/06/1999 12:11:03] Reading a fine mcp.com book byQuePERL5BYEXAMPLE . Bookshelf PERL 5 BY EXAMPLE By Group Que ISBN: 0789708663 Published: 03-Oct -1 996 Retail Price: $40 US Buy this Book This will open in a new browser window. Reading a fine mcp.com book by Que PERL 5 BY. and -p Options❍ Example: Using the -i Option❍ Example: Using the -s Option❍ ● Summary● Review Questions● Review Exercises● Reading a fine mcp.com book by Que PERL 5 BY EXAMPLE http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html. and Modules● Module Examples Example: The Carp Module❍ Example: The English Module❍ Example: The Env Module❍ ● Summary● Reading a fine mcp.com book by Que PERL 5 BY EXAMPLE http://www.pbs.mcp.com/ebooks/0789708663/viewabookab.html