|
发表于 2007-5-25 10:36:35
|
显示全部楼层
Preface ..................................................................................................................... xi
1. Introduction ................................................................................................ 1
Questions and Answers ................................................................................... 1
What Does “Perl” Stand For? ........................................................................... 4
How Can I Get Perl? ........................................................................................ 8
How Do I Make a Perl Program? .................................................................. 12
A Whirlwind Tour of Perl .............................................................................. 17
Exercises ......................................................................................................... 18
2. Scalar Data ............................................................................................... 19
What Is Scalar Data? ....................................................................................... 19
Numbers ......................................................................................................... 19
Strings ............................................................................................................. 22
Perl’s Built-in Warnings ................................................................................. 26
Scalar Variables .............................................................................................. 27
Output with print ........................................................................................... 29
The if Control Structure ................................................................................. 34
Getting User Input ......................................................................................... 35
The chomp Operator ..................................................................................... 36
The while Control Structure .......................................................................... 37
The undef Value ............................................................................................ 37
The defined Function .................................................................................... 38
Exercises ......................................................................................................... 39
vi Table of Contents
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates Inc All rights reserved
3. Lists and Arrays ....................................................................................... 40
Accessing Elements of an Array .................................................................... 41
Special Array Indices ..................................................................................... 42
List Literals ...................................................................................................... 43
List Assignment .............................................................................................. 45
Interpolating Arrays into Strings .................................................................... 47
The foreach Control Structure ....................................................................... 48
Perl’s Favorite Default: $_ .............................................................................. 49
Scalar and List Context .................................................................................. 51
<STDIN> in List Context ................................................................................ 54
Exercises ......................................................................................................... 55
4. Subroutines ............................................................................................... 56
System and User Functions ........................................................................... 56
Defining a Subroutine .................................................................................... 57
Invoking a Subroutine ................................................................................... 57
Return Values ................................................................................................. 58
Arguments ...................................................................................................... 60
Private Variables in Subroutines .................................................................... 62
The local Operator ......................................................................................... 63
Variable-length Parameter Lists ..................................................................... 64
Notes on Lexical (my) Variables ................................................................... 67
The use strict Pragma .................................................................................... 68
The return Operator ....................................................................................... 69
Exercises ......................................................................................................... 71
5. Hashes ......................................................................................................... 73
What Is a Hash? .............................................................................................. 73
Hash Element Access ..................................................................................... 76
Hash Functions ............................................................................................... 80
Typical Use of a Hash .................................................................................... 83
Exercises ......................................................................................................... 84
6. I/O Basics ................................................................................................... 86
Input from Standard Input ............................................................................. 86
Input from the Diamond Operator ............................................................... 88
The Invocation Arguments ............................................................................ 90
Output to Standard Output ........................................................................... 91
Formatted Output with printf ........................................................................ 94
Exercises ......................................................................................................... 96
Table of Contents vii
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates Inc All rights reserved
7. Concepts of Regular Expressions ...................................................... 98
What Are Regular Expressions? ..................................................................... 98
Using Simple Patterns .................................................................................. 100
A Pattern Test Program ................................................................................ 102
Exercises ....................................................................................................... 103
8. More About Regular Expressions ................................................... 105
Character Classes .......................................................................................... 105
General Quantifiers ...................................................................................... 107
Anchors ......................................................................................................... 108
Memory Parentheses .................................................................................... 109
Precedence ................................................................................................... 111
Exercises ....................................................................................................... 113
9. Using Regular Expressions ............................................................... 115
Matches with m// ......................................................................................... 115
Option Modifiers .......................................................................................... 116
The Binding Operator, =~ ........................................................................... 117
Interpolating into Patterns ........................................................................... 118
The Match Variables .................................................................................... 119
Substitutions with s/// ................................................................................. 122
The split Operator ........................................................................................ 125
The join Function ......................................................................................... 126
Exercises ....................................................................................................... 127
10. More Control Structures ..................................................................... 128
The unless Control Structure ....................................................................... 128
The until Control Structure .......................................................................... 129
Expression Modifiers .................................................................................... 130
The Naked Block Control Structure ............................................................ 131
The elsif Clause ............................................................................................ 132
Autoincrement and Autodecrement ............................................................ 133
The for Control Structure ............................................................................. 135
Loop Controls ............................................................................................... 138
Logical Operators ......................................................................................... 142
Exercise ......................................................................................................... 147
11. Filehandles and File Tests .................................................................. 148
What Is a Filehandle? ................................................................................... 148
Opening a Filehandle .................................................................................. 150
Fatal Errors with die ..................................................................................... 152
viii Table of Contents
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates Inc All rights reserved
Using Filehandles ......................................................................................... 155
Reopening a Standard Filehandle ............................................................... 157
File Tests ....................................................................................................... 157
Exercises ....................................................................................................... 167
12. Directory Operations ........................................................................... 168
Moving Around the Directory Tree ............................................................. 168
Globbing ....................................................................................................... 169
An Alternate Syntax for Globbing ............................................................... 170
Directory Handles ........................................................................................ 171
Recursive Directory Listing .......................................................................... 173
Exercises ....................................................................................................... 173
13. Manipulating Files and Directories .............................................. 174
Removing Files ............................................................................................. 174
Renaming Files ............................................................................................. 176
Links and Files ............................................................................................. 177
Making and Removing Directories .............................................................. 182
Modifying Permissions ................................................................................. 184
Changing Ownership ................................................................................... 184
Changing Timestamps .................................................................................. 185
Using Simple Modules ................................................................................. 185
Exercises ....................................................................................................... 190
14. Process Management ........................................................................... 192
The system Function .................................................................................... 192
The exec Function ....................................................................................... 195
The Environment Variables ......................................................................... 196
Using Backquotes to Capture Output ......................................................... 197
Processes as Filehandles .............................................................................. 201
Getting Down and Dirty with Fork ............................................................. 203
Sending and Receiving Signals .................................................................... 204
Exercises ....................................................................................................... 206
15. Strings and Sorting .............................................................................. 208
Finding a Substring with index ................................................................... 208
Manipulating a Substring with substr .......................................................... 209
Formatting Data with sprintf ....................................................................... 211
Advanced Sorting ......................................................................................... 213
Exercises ....................................................................................................... 219
Table of Contents ix
Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition
Copyright © 2001 O’Reilly & Associates Inc All rights reserved
16. Simple Databases ................................................................................. 221
DBM Files and DBM Hashes ....................................................................... 221
Manipulating Data with pack and unpack ................................................. 224
Fixed-length Random-access Databases ..................................................... 225
Variable-length (Text) Databases ................................................................ 228
Exercises ....................................................................................................... 232
17. Some Advanced Perl Techniques ..................................................... 233
Trapping Errors with eval ............................................................................ 233
Picking Items from a List with grep ............................................................ 236
Transforming Items from a List with map .................................................. 237
Unquoted Hash Keys ................................................................................... 238
More Powerful Regular Expressions ........................................................... 239
Slices ............................................................................................................. 242
Exercise ......................................................................................................... 247 |
|