Preface |
|
xxv | |
1 The Practical Extraction and Report Language |
|
1 | (14) |
|
|
1 | (1) |
|
1.2 What Is an Interpreted Language? |
|
|
2 | (1) |
|
|
3 | (3) |
|
|
4 | (1) |
|
1.3.2 What Are Perl 6, Rakudo Perl, and Parrot? |
|
|
4 | (2) |
|
|
6 | (3) |
|
|
6 | (1) |
|
1.4.2 Downloads and Other Resources for Perl (perl.org) |
|
|
7 | (1) |
|
1.4.3 ActivePerl (activestate.com) |
|
|
8 | (1) |
|
1.4.4 What Version Do I Have? |
|
|
9 | (1) |
|
|
9 | (4) |
|
1.5.1 Where to Find the Most Complete Documentation from Perl |
|
|
9 | (1) |
|
|
10 | (2) |
|
1.5.3 Online Documentation |
|
|
12 | (1) |
|
|
13 | (1) |
|
|
13 | (2) |
2 Perl Quick Start |
|
15 | (18) |
|
2.1 Quick Start, Quick Reference |
|
|
15 | (17) |
|
2.1.1 A Note to Programmers |
|
|
15 | (1) |
|
2.1.2 A Note to Non-Programmers |
|
|
15 | (1) |
|
2.1.3 Perl Syntax and Constructs |
|
|
15 | (18) |
|
|
28 | (1) |
|
Passing Arguments at the Command Line |
|
|
29 | (1) |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
31 | (1) |
|
|
32 | (1) |
|
|
32 | (1) |
3 Perl Scripts |
|
33 | (16) |
|
|
33 | (4) |
|
3.1.1 Finding a Text Editor |
|
|
34 | (1) |
|
3.1.2 Naming Perl Scripts |
|
|
35 | (1) |
|
3.1.3 Statements, Whitespace, and Linebreaks |
|
|
35 | (1) |
|
3.1.4 Strings and Numbers |
|
|
36 | (1) |
|
|
37 | (1) |
|
3.3 Variables (Where to Put Data) |
|
|
37 | (5) |
|
|
38 | (1) |
|
|
38 | (1) |
|
|
39 | (1) |
|
3.3.4 Using Perl Built-in Functions |
|
|
39 | (1) |
|
|
40 | (2) |
|
|
42 | (2) |
|
3.4.1 What Kinds of Errors to Expect |
|
|
43 | (1) |
|
|
44 | (3) |
|
3.5.1 The -e Switch (Quick Test at the Command Line) |
|
|
45 | (1) |
|
3.5.2 The -c Switch (Check Syntax) |
|
|
46 | (1) |
|
3.5.3 The -w Switch (Warnings) |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
Exercise 3 Getting with It Syntactically |
|
|
48 | (1) |
4 Getting a Handle on Printing |
|
49 | (32) |
|
4.1 The Special Filehandles STDOUT, STDIN, STDERR |
|
|
49 | (2) |
|
|
51 | (1) |
|
|
51 | (18) |
|
|
52 | (7) |
|
|
53 | (1) |
|
|
54 | (1) |
|
|
54 | (1) |
|
Perl's Alternative Quotes |
|
|
55 | (4) |
|
4.3.2 Literals (Numeric, String, and Special) |
|
|
59 | (7) |
|
|
60 | (1) |
|
|
61 | (2) |
|
|
63 | (3) |
|
4.3.3 Printing Without Quotes—The here document |
|
|
66 | (3) |
|
|
67 | (2) |
|
4.4 Fancy Formatting with the printf Function |
|
|
69 | (5) |
|
4.4.1 Saving Formatting with the sprintf Function |
|
|
73 | (1) |
|
4.4.2 The No Newline say Function |
|
|
73 | (1) |
|
|
74 | (4) |
|
|
74 | (1) |
|
4.5.2 The warnings Pragma |
|
|
75 | (1) |
|
4.5.3 The diagnostics Pragma |
|
|
76 | (1) |
|
4.5.4 The strict Pragma and Words |
|
|
77 | (1) |
|
|
78 | (1) |
|
|
79 | (1) |
|
Exercise 4 A String of Perk |
|
|
79 | (2) |
5 What's In a Name? |
|
81 | (64) |
|
5.1 More About Data Types |
|
|
81 | (6) |
|
5.1.1 Basic Data Types (Scalar, Array, Hash) |
|
|
81 | (1) |
|
5.1.2 Package, Scope, Privacy, and Strictness |
|
|
82 | (3) |
|
|
82 | (3) |
|
|
85 | (1) |
|
5.1.4 Assignment Statements |
|
|
86 | (1) |
|
5.2 Scalars, Arrays, and Hashes |
|
|
87 | (18) |
|
|
88 | (3) |
|
|
88 | (1) |
|
|
89 | (1) |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
91 | (8) |
|
|
92 | (1) |
|
Output and Input Special Variables ($, and $") |
|
|
93 | (1) |
|
|
94 | (1) |
|
The Range Operator and Array Assignment |
|
|
95 | (1) |
|
|
95 | (2) |
|
Looping Through an Array with the foreach Loop |
|
|
97 | (1) |
|
|
98 | (1) |
|
Multidimensional Arrays-Lists of Lists |
|
|
99 | (1) |
|
5.2.3 Hashes-Unordered Lists |
|
|
99 | (5) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (1) |
|
Removing Duplicates from a List Using a Hash |
|
|
103 | (1) |
|
5.2.4 Complex Data Structures |
|
|
104 | (1) |
|
|
105 | (20) |
|
5.3.1 Adding Elements to an Array |
|
|
105 | (1) |
|
|
105 | (1) |
|
|
106 | (1) |
|
5.3.2 Removing and Replacing Elements |
|
|
106 | (5) |
|
|
106 | (1) |
|
|
107 | (2) |
|
|
109 | (1) |
|
|
110 | (1) |
|
|
111 | (1) |
|
The chop and chomp Functions (with Lists) |
|
|
111 | (1) |
|
5.3.4 Searching for Elements and Index Values |
|
|
112 | (2) |
|
|
112 | (2) |
|
5.3.5 Creating a List from a Scalar |
|
|
114 | (4) |
|
|
114 | (4) |
|
5.3.6 Creating a Scalar from a List |
|
|
118 | (1) |
|
|
118 | (1) |
|
5.3.7 Transforming an Array |
|
|
119 | (2) |
|
|
119 | (2) |
|
|
121 | (3) |
|
|
121 | (3) |
|
5.3.9 Checking the Existence of an Array Index Value |
|
|
124 | (1) |
|
|
124 | (1) |
|
5.3.10 Reversing an Array |
|
|
125 | (1) |
|
|
125 | (1) |
|
5.4 Hash (Associative Array) Functions |
|
|
125 | (15) |
|
|
125 | (1) |
|
5.4.2 The values Function |
|
|
126 | (2) |
|
|
128 | (1) |
|
5.4.4 Removing Duplicates from a List with a Hash |
|
|
129 | (1) |
|
5.4.5 Sorting a Hash by Keys and Values |
|
|
130 | (5) |
|
Sort Hash by Keys in Ascending Order |
|
|
130 | (1) |
|
Sort Hash by Keys in Reverse Order |
|
|
131 | (1) |
|
Sort Hash by Keys Numerically |
|
|
132 | (1) |
|
Numerically Sort a Hash by Values in Ascending Order |
|
|
133 | (1) |
|
Numerically Sort a Hash by Values in Descending Order |
|
|
134 | (1) |
|
5.4.6 The delete Function |
|
|
135 | (1) |
|
5.4.7 The exists function |
|
|
136 | (1) |
|
|
137 | (2) |
|
|
137 | (1) |
|
|
138 | (1) |
|
|
139 | (1) |
|
|
139 | (1) |
|
|
140 | (1) |
|
|
141 | (1) |
|
Exercise 5 The Funny Characters |
|
|
141 | (4) |
6 Where's the Operator? |
|
145 | (36) |
|
6.1 About Perl Operators—More Context |
|
|
145 | (3) |
|
6.1.1 Evaluating an Expression |
|
|
147 | (1) |
|
|
148 | (1) |
|
6.3 Precedence and Associativity |
|
|
149 | (29) |
|
6.3.1 Assignment Operators |
|
|
151 | (2) |
|
|
153 | (1) |
|
6.3.3 Relational Operators |
|
|
154 | (2) |
|
|
154 | (1) |
|
|
155 | (1) |
|
6.3.4 Conditional Operators |
|
|
156 | (1) |
|
|
157 | (3) |
|
|
157 | (2) |
|
|
159 | (1) |
|
6.3.6 The Smartmatch Operator |
|
|
160 | (2) |
|
6.3.7 Logical Operators (Short-Circuit Operators) |
|
|
162 | (2) |
|
6.3.8 Logical Word Operators |
|
|
164 | (2) |
|
6.3.9 Arithmetic Operators and Functions |
|
|
166 | (6) |
|
|
166 | (1) |
|
|
167 | (5) |
|
6.3.10 Autoincrement and Autodecrement Operators |
|
|
172 | (1) |
|
6.3.11 Bitwise Logical Operators |
|
|
173 | (2) |
|
|
173 | (1) |
|
|
174 | (1) |
|
|
175 | (1) |
|
6.3.13 Special String Operators and Functions |
|
|
176 | (2) |
|
|
178 | (1) |
|
|
179 | (1) |
|
Exercise 6 Operator, Operator |
|
|
179 | (2) |
7 If Only, Unconditionally, Forever |
|
181 | (38) |
|
7.1 Control Structures, Blocks, and Compound Statements |
|
|
182 | (6) |
|
7.1.1 Decision Making—Conditional Constructs |
|
|
183 | (5) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
The if/elsif/else Construct |
|
|
185 | (1) |
|
|
186 | (2) |
|
7.2 Statement Modifiers and Simple Statements |
|
|
188 | (2) |
|
|
188 | (1) |
|
7.2.2 The unless Modifier |
|
|
189 | (1) |
|
7.3 Repetition with Loops |
|
|
190 | (12) |
|
|
190 | (2) |
|
|
192 | (2) |
|
7.3.3 The do/while and do/until Loops |
|
|
194 | (2) |
|
7.3.4 The for Loop (The Three-Part Loop) |
|
|
196 | (2) |
|
7.3.5 The foreach (for) Loop |
|
|
198 | (4) |
|
|
202 | (15) |
|
|
202 | (1) |
|
7.4.2 The foreach Modifier |
|
|
203 | (1) |
|
|
204 | (8) |
|
|
204 | (1) |
|
The redo and goto Statements |
|
|
205 | (3) |
|
|
208 | (2) |
|
|
210 | (2) |
|
7.4.4 The switch Statement (given/when) |
|
|
212 | (7) |
|
The switch Feature (given/when/say) |
|
|
214 | (3) |
|
|
217 | (1) |
|
|
217 | (1) |
|
Exercise 7 What Are Your Conditions? |
|
|
218 | (1) |
8 Regular Expressions—Pattern Matching |
|
219 | (26) |
|
8.1 What Is a Regular Expression? |
|
|
219 | (2) |
|
8.1.1 Why Do We Need Regular Expressions? |
|
|
220 | (1) |
|
8.2 Modifiers and Simple Statements with Regular Expressions |
|
|
221 | (4) |
|
8.2.1 Pattern Binding Operators |
|
|
222 | (1) |
|
8.2.2 The DATA Filehandle |
|
|
223 | (2) |
|
8.3 Regular Expression Operators |
|
|
225 | (18) |
|
8.3.1 The m Operator and Pattern Matching |
|
|
225 | (7) |
|
The g Modifier—Global Match |
|
|
229 | (1) |
|
The i Modifier—Case Insensitivity |
|
|
230 | (1) |
|
Special Scalars for Saving Patterns |
|
|
230 | (1) |
|
The x Modifier—The Expressive Modifier |
|
|
231 | (1) |
|
8.3.2 The s Operator and Substitution |
|
|
232 | (1) |
|
8.3.3 The Pattern Binding Operators with Substitution |
|
|
232 | (15) |
|
Changing the Substitution Delimiters |
|
|
234 | (1) |
|
|
235 | (5) |
|
Using the Special $& Variable in a Substitution |
|
|
240 | (1) |
|
Pattern Matching with a Real File |
|
|
241 | (2) |
|
|
243 | (1) |
|
|
243 | (1) |
|
Exercise 8 A Match Made in Heaven |
|
|
244 | (1) |
9 Getting Control—Regular Expression Metacharacters |
|
245 | (52) |
|
9.1 The RegExLib.com Library |
|
|
245 | (2) |
|
9.2 Regular Expression Metacharacters |
|
|
247 | (43) |
|
9.2.1 Metacharacters for Single Characters |
|
|
251 | (7) |
|
|
251 | (1) |
|
The s Modifier—The Dot Metacharacter and the Newline |
|
|
252 | (1) |
|
|
253 | (4) |
|
The POSIX Bracket Expressions |
|
|
257 | (1) |
|
9.2.2 Whitespace Metacharacters |
|
|
258 | (3) |
|
9.2.3 Metacharacters to Repeat Pattern Matches |
|
|
261 | (24) |
|
|
261 | (6) |
|
Metacharacters That Turn off Greediness |
|
|
267 | (2) |
|
|
269 | (2) |
|
|
271 | (2) |
|
|
273 | (1) |
|
|
273 | (3) |
|
|
276 | (4) |
|
|
280 | (1) |
|
|
281 | (1) |
|
Metacharacters That Look Ahead and Behind |
|
|
282 | (3) |
|
9.2.4 The tr or y Operators |
|
|
285 | (5) |
|
|
288 | (1) |
|
|
289 | (1) |
|
|
290 | (1) |
|
|
290 | (4) |
|
|
291 | (3) |
|
|
294 | (1) |
|
|
295 | (1) |
|
Exercise 9 And the Search Goes On |
|
|
295 | (2) |
10 Getting a Handle on Files |
|
297 | (50) |
|
10.1 The User-Defined Filehandle |
|
|
297 | (10) |
|
10.1.1 Opening Files—The open Function |
|
|
297 | (1) |
|
10.1.2 Opening for Reading |
|
|
298 | (2) |
|
|
299 | (1) |
|
|
299 | (1) |
|
10.1.3 Reading from a File and Scalar Assignment |
|
|
300 | (6) |
|
|
300 | (1) |
|
The Filehandle and a User-Defined Scalar Variable |
|
|
301 | (1) |
|
"Slurping" a File into an Array |
|
|
302 | (1) |
|
Using map to Create Fields from a File |
|
|
303 | (1) |
|
Slurping a File into a String with the read Function |
|
|
304 | (2) |
|
10.1.4 Loading a Hash from a File |
|
|
306 | (1) |
|
|
307 | (26) |
|
10.2.1 Assigning Input to a Scalar Variable |
|
|
307 | (1) |
|
10.2.2 The chop and chomp Functions |
|
|
308 | (1) |
|
|
309 | (1) |
|
|
310 | (1) |
|
10.2.5 Assigning Input to an Array |
|
|
311 | (1) |
|
10.2.6 Assigning Input to a Hash |
|
|
312 | (1) |
|
10.2.7 Opening for Writing |
|
|
313 | (2) |
|
10.2.8 Win32 Binary Files |
|
|
315 | (1) |
|
10.2.9 Opening for Appending |
|
|
316 | (1) |
|
10.2.10 The select Function |
|
|
317 | (1) |
|
10.2.11 File Locking with flock |
|
|
317 | (2) |
|
10.2.12 The seek and tell Functions |
|
|
319 | (5) |
|
|
319 | (3) |
|
|
322 | (2) |
|
10.2.13 Opening for Reading and Writing |
|
|
324 | (2) |
|
10.2.14 Opening for Anonymous Pipes |
|
|
326 | (7) |
|
|
327 | (2) |
|
Sending the Output of a Filter to a File |
|
|
329 | (1) |
|
|
330 | (3) |
|
|
333 | (9) |
|
|
333 | (1) |
|
10.3.2 ARGV and the Null Filehandle |
|
|
334 | (4) |
|
|
338 | (2) |
|
10.3.4 The -i Switch—Editing Files in Place |
|
|
340 | (2) |
|
|
342 | (2) |
|
10.5 What You Should Know |
|
|
344 | (1) |
|
|
344 | (1) |
|
Exercise 10 Getting a Handle on Things |
|
|
345 | (2) |
11 How Do Subroutines Function? |
|
347 | (30) |
|
11.1 Subroutines/Functions |
|
|
348 | (4) |
|
11.1.1 Defining and Calling a Subroutine |
|
|
349 | (3) |
|
|
351 | (1) |
|
|
351 | (1) |
|
11.2 Passing Arguments and the @_ Array |
|
|
352 | (21) |
|
11.2.1 Call-by-Reference and the @_ Array |
|
|
353 | (1) |
|
11.2.2 Assigning Values from @_ |
|
|
353 | (3) |
|
Passing a Hash to a Subroutine |
|
|
355 | (1) |
|
|
356 | (1) |
|
11.2.4 Scoping Operators: local, my, our, and state |
|
|
357 | (4) |
|
|
358 | (1) |
|
|
358 | (3) |
|
11.2.5 Using the strict Pragma (my and our) |
|
|
361 | (3) |
|
|
363 | (1) |
|
11.2.6 Putting It All Together |
|
|
364 | (1) |
|
|
365 | (1) |
|
11.2.8 Context and Subroutines |
|
|
366 | (3) |
|
The wantarray Function and User-Defined Subroutines |
|
|
367 | (2) |
|
|
369 | (2) |
|
11.2.10 BEGIN and END Blocks (Startup and Finish) |
|
|
371 | (1) |
|
11.2.11 The subs Function |
|
|
371 | (2) |
|
11.3 What You Should Know |
|
|
373 | (1) |
|
|
373 | (1) |
|
Exercise 11 I Can't Seem to Function Without Subroutines |
|
|
374 | (3) |
12 Does This Job Require a Reference? |
|
377 | (30) |
|
12.1 What Is a Reference? |
|
|
377 | (27) |
|
|
378 | (4) |
|
|
379 | (1) |
|
Dereferencing the Pointer |
|
|
379 | (3) |
|
12.1.2 References and Anonymous Variables |
|
|
382 | (1) |
|
|
382 | (1) |
|
|
383 | (1) |
|
12.1.3 Nested Data Structures |
|
|
383 | (8) |
|
|
384 | (1) |
|
|
385 | (2) |
|
|
387 | (2) |
|
|
389 | (2) |
|
12.1.4 More Nested Structures |
|
|
391 | (2) |
|
12.1.5 References and Subroutines |
|
|
393 | (3) |
|
|
393 | (1) |
|
Subroutines and Passing by Reference |
|
|
394 | (2) |
|
|
396 | (2) |
|
12.1.7 Symbolic References |
|
|
398 | (2) |
|
|
400 | (1) |
|
12.1.8 Typeglobs (Aliases) |
|
|
400 | (7) |
|
Filehandle References and Typeglobs |
|
|
402 | (2) |
|
12.2 What You Should Know |
|
|
404 | (1) |
|
|
404 | (1) |
|
Exercise 12 It's Not Polite to Point! |
|
|
405 | (2) |
13 Modularize It, Package It, and Send It to the Library! |
|
407 | (40) |
|
13.1 Before Getting Started |
|
|
407 | (10) |
|
|
408 | (1) |
|
13.1.2 What Is a Package? |
|
|
408 | (3) |
|
Referencing Package Variables and Subroutines from Another Package |
|
|
409 | (2) |
|
|
411 | (1) |
|
|
412 | (5) |
|
13.2 The Standard Perl Library |
|
|
417 | (19) |
|
|
418 | (2) |
|
Setting the PERL5LIB Environment Variable |
|
|
419 | (1) |
|
|
420 | (1) |
|
13.2.2 Packages and .pm Files |
|
|
420 | (4) |
|
|
421 | (1) |
|
The use Function (Modules and Pragmas) |
|
|
421 | (1) |
|
Using Perl to Include Your Own Library |
|
|
422 | (2) |
|
13.2.3 Exporting and Importing |
|
|
424 | (3) |
|
|
424 | (3) |
|
13.2.4 Finding Modules and Documentation from the Standard Perl Library |
|
|
427 | (4) |
|
Viewing the Contents of the Carp.pm Module |
|
|
428 | (3) |
|
13.2.5 How to "Use" a Module from the Standard Perl Library |
|
|
431 | (1) |
|
13.2.6 Using Perl to Create Your Own Module |
|
|
432 | (4) |
|
Creating an Import Method Without Exporter |
|
|
435 | (1) |
|
|
436 | (5) |
|
13.3.1 The CPAN.pm Module |
|
|
437 | (2) |
|
Retrieving a Module from CPAN with the cpan Shell |
|
|
438 | (1) |
|
13.3.2 Using Perl Program Manager |
|
|
439 | (2) |
|
13.4 Using Perlbrew and CPAN Minus |
|
|
441 | (3) |
|
13.5 What You Should Know |
|
|
444 | (1) |
|
|
445 | (1) |
|
Exercise 13 I Hid All My Perls in a Package |
|
|
445 | (2) |
14 Bless Those Things! (Object-Oriented Perl) |
|
447 | (72) |
|
|
447 | (3) |
|
|
447 | (1) |
|
|
448 | (1) |
|
14.1.3 Some Object-Oriented Lingo |
|
|
449 | (1) |
|
14.2 Perl Classes, Objects, and Methods—Relating to the Real World |
|
|
450 | (28) |
|
|
451 | (1) |
|
14.2.2 A Complete Object-Oriented Perl Program |
|
|
451 | (3) |
|
A Perl Package Is a Class |
|
|
453 | (1) |
|
|
453 | (1) |
|
|
454 | (2) |
|
|
454 | (1) |
|
|
454 | (2) |
|
14.2.4 Methods Are Perl Subroutines |
|
|
456 | (8) |
|
|
456 | (1) |
|
|
457 | (1) |
|
|
457 | (1) |
|
Creating the Object with a Constructor |
|
|
458 | (2) |
|
Creating the Instance Methods |
|
|
460 | (2) |
|
Invoking the Methods (User Interaction) |
|
|
462 | (2) |
|
14.2.5 Creating an Object-Oriented Module |
|
|
464 | (8) |
|
Passing Arguments to Methods |
|
|
466 | (1) |
|
Passing Parameters to Instance Methods |
|
|
467 | (3) |
|
Named Parameters and Data Checking |
|
|
470 | (2) |
|
14.2.6 Polymorphism and Runtime Binding |
|
|
472 | (4) |
|
14.2.7 Destructors and Garbage Collection |
|
|
476 | (2) |
|
14.3 Anonymous Subroutines, Closures, and Privacy |
|
|
478 | (6) |
|
14.3.1 What Is a Closure? |
|
|
478 | (3) |
|
14.3.2 Closures and Objects |
|
|
481 | (3) |
|
|
484 | (17) |
|
14.4.1 The @ISA Array and Calling Methods |
|
|
484 | (2) |
|
14.4.2 $AUTOLOAD, sub AUTOLOAD, and UNIVERSAL |
|
|
486 | (3) |
|
|
489 | (7) |
|
14.4.4 Multiple Inheritance and Roles with Moose |
|
|
496 | (3) |
|
14.4.5 Overriding a Parent Method and the SUPER Pseudo Class |
|
|
499 | (2) |
|
14.5 Plain Old Documentation—Documenting a Module |
|
|
501 | (7) |
|
|
502 | (2) |
|
|
504 | (2) |
|
Checking Your pod Commands |
|
|
504 | (2) |
|
14.5.3 How to Use the pod Interpreters |
|
|
506 | (1) |
|
14.5.4 Translating pod Documentation into Text |
|
|
506 | (1) |
|
14.5.5 Translating pod Documentation into HTML |
|
|
507 | (1) |
|
14.6 Using Objects from the Perl Library |
|
|
508 | (4) |
|
14.6.1 An Object-Oriented Module from the Standard Pee Library |
|
|
509 | (2) |
|
14.6.2 Using a Module with Objects from the Standard Perl Library |
|
|
511 | (1) |
|
14.7 What You Should Know |
|
|
512 | (1) |
|
|
513 | (1) |
|
Exercise 14 What's the Object of This Lesson? |
|
|
513 | (6) |
15 Pert Connects with MySQL |
|
519 | (76) |
|
|
519 | (1) |
|
15.2 What Is a Relational Database? |
|
|
520 | (10) |
|
15.2.1 Client/Server Databases |
|
|
521 | (1) |
|
15.2.2 Components of a Relational Database |
|
|
522 | (6) |
|
|
523 | (1) |
|
|
523 | (1) |
|
|
523 | (1) |
|
|
524 | (3) |
|
|
527 | (1) |
|
15.2.3 Talking to the Database with SQL |
|
|
528 | (2) |
|
|
528 | (1) |
|
Semicolons Terminate SQL Statements |
|
|
529 | (1) |
|
|
529 | (1) |
|
|
529 | (1) |
|
|
529 | (1) |
|
|
530 | (1) |
|
15.3 Getting Started with MySQL |
|
|
530 | (26) |
|
|
531 | (1) |
|
15.3.2 Connecting to MySQL |
|
|
532 | (2) |
|
Editing Keys at the MySQL Console |
|
|
533 | (1) |
|
|
533 | (1) |
|
15.3.3 Graphical User Tools |
|
|
534 | (3) |
|
|
534 | (2) |
|
The MySQL Privilege System |
|
|
536 | (1) |
|
15.3.4 Finding the Databases |
|
|
537 | (2) |
|
Creating and Dropping a Database |
|
|
538 | (1) |
|
15.3.5 Getting Started with Basic Commands |
|
|
539 | (17) |
|
Creating a Database with MySQL |
|
|
539 | (2) |
|
Selecting a Database with MySQL |
|
|
541 | (1) |
|
Creating a Table in the Database |
|
|
541 | (1) |
|
|
541 | (2) |
|
Adding Another Table with a Primary Key |
|
|
543 | (1) |
|
Inserting Data into Tables |
|
|
544 | (2) |
|
Selecting Data from Tables—The SELECT Command |
|
|
546 | (1) |
|
|
546 | (1) |
|
|
547 | (1) |
|
|
548 | (2) |
|
|
550 | (1) |
|
|
551 | (1) |
|
|
552 | (1) |
|
|
553 | (1) |
|
|
554 | (1) |
|
|
555 | (1) |
|
|
555 | (1) |
|
15.4 What Is the Perl DBI? |
|
|
556 | (23) |
|
15.4.1 Installing the DBD Driver |
|
|
556 | (2) |
|
Without the DBD-MySQL with PPM |
|
|
556 | (2) |
|
|
558 | (1) |
|
Installing the DBD::mysql Driver from CPAN |
|
|
558 | (1) |
|
15.4.2 The DBI Class Methods |
|
|
558 | (2) |
|
|
560 | (1) |
|
15.4.4 Connecting to and Disconnecting from the Database |
|
|
561 | (2) |
|
|
561 | (2) |
|
|
563 | (1) |
|
15.4.5 Preparing a Statement Handle and Fetching Results |
|
|
563 | (4) |
|
Select, Execute, and Dump the Results |
|
|
563 | (1) |
|
Select, Execute, and Fetch a Row As an Array |
|
|
564 | (2) |
|
Select, Execute, and Fetch a Row As a Hash |
|
|
566 | (1) |
|
15.4.6 Getting Error Messages |
|
|
567 | (4) |
|
|
567 | (1) |
|
|
567 | (2) |
|
Binding Columns and Fetching Values |
|
|
569 | (2) |
|
15.4.7 The ? Placeholder and Parameter Binding |
|
|
571 | (5) |
|
Binding Parameters in the execute Statement |
|
|
571 | (3) |
|
Binding Parameters and the bind_param() Method |
|
|
574 | (2) |
|
|
576 | (1) |
|
|
577 | (2) |
|
15.5 Statements That Don't Return Anything |
|
|
579 | (4) |
|
|
579 | (4) |
|
|
579 | (1) |
|
|
580 | (1) |
|
|
581 | (2) |
|
|
583 | (7) |
|
15.6.1 Commit and Rollback |
|
|
583 | (2) |
|
15.6.2 Perl DBI, the Web, and the Dancer Framework |
|
|
585 | (5) |
|
|
590 | (1) |
|
15.8 What You Should Know |
|
|
591 | (1) |
|
|
591 | (1) |
|
Exercise 15 Practicing Queries and Using DBI |
|
|
592 | (3) |
16 Interfacing with the System |
|
595 | (80) |
|
|
595 | (34) |
|
16.1.1 Directories and Files |
|
|
597 | (2) |
|
|
597 | (1) |
|
|
598 | (1) |
|
16.1.2 Directory and File Attributes |
|
|
599 | (4) |
|
|
599 | (1) |
|
|
600 | (3) |
|
16.1.3 Finding Directories and Files |
|
|
603 | (2) |
|
16.1.4 Creating a Directory—The mkdir Function |
|
|
605 | (2) |
|
|
605 | (1) |
|
|
605 | (2) |
|
16.1.5 Removing a Directory—The rmdir Function |
|
|
607 | (1) |
|
16.1.6 Changing Directories—The chdir Function |
|
|
607 | (1) |
|
16.1.7 Accessing a Directory via the Directory Filehandle |
|
|
608 | (4) |
|
|
609 | (1) |
|
|
609 | (1) |
|
|
610 | (1) |
|
|
611 | (1) |
|
|
611 | (1) |
|
|
611 | (1) |
|
16.1.8 Permissions and Ownership |
|
|
612 | (4) |
|
|
612 | (1) |
|
|
612 | (2) |
|
The chmod Function (UNIX) |
|
|
614 | (1) |
|
The chmod Function (Windows) |
|
|
614 | (1) |
|
The chown Function (UNIX) |
|
|
615 | (1) |
|
The umask Function (UNIX) |
|
|
616 | (1) |
|
16.1.9 Hard and Soft Links |
|
|
616 | (4) |
|
|
616 | (1) |
|
|
617 | (1) |
|
The link and unlink Functions (UNIX) |
|
|
618 | (1) |
|
The symlink and readlink Functions (UNIX) |
|
|
619 | (1) |
|
|
620 | (1) |
|
The rename Function (UNIX and Windows) |
|
|
620 | (1) |
|
16.1.11 Changing Access and Modification Times |
|
|
620 | (1) |
|
|
620 | (1) |
|
|
621 | (3) |
|
The stat and lstat Functions |
|
|
621 | (3) |
|
16.1.13 Packing and Unpacking Data |
|
|
624 | (5) |
|
|
629 | (29) |
|
|
629 | (2) |
|
|
631 | (1) |
|
16.2.3 The Environment (UNIX and Windows) |
|
|
632 | (2) |
|
16.2.4 Processes and Filehandles |
|
|
634 | (3) |
|
Login Information—The getlogin Function |
|
|
635 | (1) |
|
Special Process Variables (pid, uid, euid, gid, egid) |
|
|
635 | (1) |
|
The Parent Process ID—The getppid Function and the $$ Variable |
|
|
635 | (1) |
|
The Process Group ID—The pgrp Function |
|
|
636 | (1) |
|
16.2.5 Process Priorities and Niceness |
|
|
637 | (1) |
|
|
637 | (1) |
|
The setpriority Function (nice) |
|
|
637 | (1) |
|
16.2.6 Password Information |
|
|
638 | (5) |
|
|
638 | (1) |
|
|
639 | (2) |
|
Getting a Password Entry (UNIX)—The getpwent Function |
|
|
641 | (1) |
|
Getting a Password Entry by Username—The getpwnam Function |
|
|
642 | (1) |
|
Getting a Password Entry by uid—The getpwuid Function |
|
|
643 | (1) |
|
16.2.7 Time and Processes |
|
|
643 | (6) |
|
|
644 | (1) |
|
|
645 | (1) |
|
The time Function (UNIX and Windows) |
|
|
646 | (1) |
|
|
646 | (2) |
|
|
648 | (1) |
|
16.2.8 Process Creation UNIX |
|
|
649 | (5) |
|
|
649 | (3) |
|
|
652 | (1) |
|
The wait and waitpid Functions |
|
|
653 | (1) |
|
|
654 | (1) |
|
16.2.9 Process Creation Win32 |
|
|
654 | (4) |
|
|
654 | (1) |
|
The Win32::Spawn Function |
|
|
655 | (1) |
|
The Win32::Process Module |
|
|
656 | (2) |
|
16.3 Other Ways to Interface with the Operating System |
|
|
658 | (6) |
|
16.3.1 The syscall Function and the h2ph Script |
|
|
658 | (1) |
|
16.3.2 Command Substitution—The Backquotes |
|
|
659 | (1) |
|
16.3.3 The Shell.pm Module |
|
|
660 | (1) |
|
16.3.4 The system Function |
|
|
661 | (2) |
|
16.3.5 Globbing (Filename Expansion and Wildcards) |
|
|
663 | (1) |
|
|
664 | (5) |
|
|
665 | (1) |
|
|
665 | (1) |
|
|
666 | (1) |
|
|
666 | (3) |
|
16.5 Signals and the %SIG Hash |
|
|
669 | (4) |
|
|
669 | (1) |
|
16.5.2 Sending Signals to Processes |
|
|
670 | (2) |
|
|
670 | (1) |
|
|
671 | (1) |
|
|
672 | (1) |
|
16.5.3 Attention, Windows Users! |
|
|
672 | (1) |
|
16.6 What You Should Know |
|
|
673 | (1) |
|
Exercise 16 Interfacing with the System |
|
|
674 | (1) |
A Perl Built-ins, Pragmas, Modules, and the Debugger |
|
675 | (48) |
|
|
675 | (30) |
|
|
705 | (3) |
|
|
708 | (2) |
|
|
710 | (6) |
|
A.5 Command-Line Switches |
|
|
716 | (2) |
|
|
718 | (5) |
|
A.6.1 Getting Information About the Debugger |
|
|
718 | (1) |
|
|
718 | (1) |
|
A.6.3 Entering and Exiting the Debugger |
|
|
719 | (1) |
|
|
720 | (3) |
B SQL Language Tutorial |
|
723 | (52) |
|
|
723 | (8) |
|
|
724 | (1) |
|
B.1.2 Executing SQL Statements |
|
|
724 | (1) |
|
|
725 | (1) |
|
B.1.3 About SQL Commands/Queries |
|
|
725 | (3) |
|
|
725 | (1) |
|
Semicolons Terminate SQL Statements |
|
|
726 | (1) |
|
|
727 | (1) |
|
|
727 | (1) |
|
|
727 | (1) |
|
|
728 | (1) |
|
B.1.4 SQL and the Database |
|
|
728 | (1) |
|
The show databases Command |
|
|
728 | (1) |
|
|
729 | (1) |
|
B.1.5 SQL Database Tables |
|
|
729 | (2) |
|
The SHOW and DESCRIBE Commands |
|
|
730 | (1) |
|
B.2 SQL Data Manipulation Language (DML) |
|
|
731 | (17) |
|
|
731 | (14) |
|
|
732 | (1) |
|
|
732 | (1) |
|
The SELECT DISTINCT Statement |
|
|
733 | (1) |
|
Limiting the Number of Lines in the Result Set with LIMIT |
|
|
734 | (2) |
|
|
736 | (1) |
|
|
737 | (1) |
|
Using the = and <> Operators |
|
|
737 | (1) |
|
|
737 | (2) |
|
|
739 | (1) |
|
|
740 | (1) |
|
The LIKE and NOT LIKE Conditions |
|
|
741 | (1) |
|
Pattern Matching and the % Wildcard |
|
|
741 | (2) |
|
|
743 | (1) |
|
|
743 | (1) |
|
Sorting Results with ORDER BY |
|
|
744 | (1) |
|
|
745 | (1) |
|
|
746 | (1) |
|
B.2.4 The DELETE Statement |
|
|
747 | (1) |
|
B.3 SQL Data Definition Language |
|
|
748 | (13) |
|
B.3.1 Creating the Database |
|
|
748 | (1) |
|
|
749 | (2) |
|
|
751 | (2) |
|
|
753 | (3) |
|
|
753 | (2) |
|
|
755 | (1) |
|
|
756 | (3) |
|
Two Tables with a Common Key |
|
|
756 | (1) |
|
Using a Fully Qualified Name and a Dot to Join the Tables |
|
|
757 | (1) |
|
|
758 | (1) |
|
|
759 | (2) |
|
|
761 | (1) |
|
B.3.8 Dropping a Database |
|
|
761 | (1) |
|
|
761 | (9) |
|
|
762 | (3) |
|
|
763 | (2) |
|
|
765 | (1) |
|
B.4.3 Date and Time Functions |
|
|
766 | (10) |
|
Formatting the Date and Time |
|
|
767 | (2) |
|
The MySQL EXTRACT Command |
|
|
769 | (1) |
|
|
770 | (1) |
|
|
770 | (1) |
|
Exercise B Do You Speak My Language? |
|
|
771 | (4) |
C Introduction to Moose (A Postmodern Object System for Perl 5) |
|
775 | (22) |
|
|
775 | (1) |
|
|
776 | (1) |
|
|
776 | (19) |
|
|
777 | (1) |
|
C.3.2 Before and After Moose Examples |
|
|
778 | (3) |
|
|
781 | (4) |
|
C.3.4 Example Using Moose and Extensions |
|
|
785 | (6) |
|
C.3.5 Example Using Inheritance with Moose |
|
|
791 | (4) |
|
|
795 | (1) |
|
|
796 | (1) |
|
|
796 | (1) |
D Perlbrew, CPAN, and cpanm |
|
797 | (10) |
|
|
797 | (5) |
|
|
798 | (1) |
|
|
798 | (2) |
|
|
799 | (1) |
|
|
800 | (1) |
|
|
801 | (7) |
|
|
801 | (1) |
|
|
802 | (1) |
|
|
803 | (2) |
|
D.4 Caveats: C Dependencies |
|
|
805 | (1) |
|
|
806 | (1) |
E Dancing with Perl |
|
807 | (24) |
|
|
808 | (21) |
|
|
811 | (3) |
|
|
814 | (4) |
|
|
818 | (8) |
|
|
826 | (3) |
|
Exercise E May I Have This Dance? |
|
|
829 | (2) |
Index |
|
831 | |