Bradley M. Kuhn - Picking Up Perl A Tutorial Book for New Perl Programmers.pdf

(354 KB) Pobierz
15446543 UNPDF
Picking Up Perl
Picking Up Perl
A Tutorial Book for New Perl Programmers
0.12th Edition, Covering Perl Version 5.6.0
Feedback and comments are always welcome. Send them to pup-comments@ebb.org
January 2001
Bradley M. Kuhn
15446543.001.png 15446543.002.png
Copyright c 1998, 1999, 2001 Bradley M. Kuhn.
Permission is granted to copy, distribute and/or modify this document under the terms of
the GNU Free Documentation License, Version 1.1 or any later version published by the
Free Software Foundation; with Invariant Sections being \The GNU Free Documentation
License", with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license
is included in the section entitled \GNU Free Documentation License" (see Appendix B
[GNU Free Documentation License], page 49 ).
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Purpose of this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Obtaining the Most Recent Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Material Covered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Conventions Used in this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 A First Perl Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Expressions, Statements, and Side-Eects . . . . . . . . . . . . . . . . . 5
2 Working with Scalars . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 Single-quoted Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1.1 Special Characters in Single-quoted Strings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.1.2 Newlines in Single-quoted Strings. . . . . . . . 9
2.1.1.3 Examples of Invalid Single-quoted Strings
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.2 A Digression|The print Function . . . . . . . . . . . . . . 10
2.1.3 Double-quoted Strings . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.3.1 Interpolation in Double-quoted Strings . . 11
2.1.3.2 Examples of Interpolation . . . . . . . . . . . . . 12
2.1.3.3 Examples of Interpolation (ASCII Octal
Values). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.3.4 Examples of Interpolation (ASCII Hex
Values). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.3.5 Characters Requiring Special Consideration
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2.1 Numeric Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2.1.1 Printing Numeric Literals . . . . . . . . . . . . . . 15
2.3 Scalar Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.1 Scalar Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.2 Undened Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4.1 Numerical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4.2 Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.4.3 Auto-Increment and Decrement . . . . . . . . . . . . . . . . . 23
2.4.4 String Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.4.5 Assignment with Operators . . . . . . . . . . . . . . . . . . . . . 23
Zgłoś jeśli naruszono regulamin