Perl Language Reference Guide
上一篇 / 下一篇 2008-12-13 11:58:44 / 个人分类:Perl
我的栏目
- 栏目:Perl
\u[1}}9~0
Table of Contents
Introduction
8vL5@O0k'QJ1M0Invocation and #!
lm@#@{&^0Basic Semantics51Testing软件测试网TZ ?2p8K[*gvI
Hello, World51Testing软件测试网"W(G&Y$Zh4o
Scalars
$j1pHc|6d#FU-l0$@%&*.
!X%Ci7Oh0Numerical Data and Operators
;T/S?J$k1O$v0Strings
:k$H] w6|H@j0Single and Double Quoting51Testing软件测试网.DE`_)qR
Comparison Operators: Arithmetic vs. String51Testing软件测试网-G B`paV6Lm
undef
&W |]"Zr%z0Lists51Testing软件测试网C?|CyX|
Subscrīpting
G9H eT8pzZ0],k!df0Array Sizes51Testing软件测试网vv.Q"Cy}p
Some Array Functions
3F^%n:YW3{F.[s0Context
7K e;Je3F*k"G D r0Control Structures51Testing软件测试网}I lWF$Wt!_H/V
If
R%E'i3l,xbht7OXD kx0Unless51Testing软件测试网JP2M U!_1S[q9L
Doing Them Backwards51Testing软件测试网/B z"X'I!w4n
And, Or
:o"Il{/eXd6m0What is Truth
_A9q6c5s1Ug0While
:n+ek:E+S0For51Testing软件测试网/HNL v\5xsq@_R
Foreach51Testing软件测试网~KF2f:H Q}
last, next, and redo
FKG$L!ex0uMo7TlfZ0Hashes
nqi7^`whR0Keys() and Values()
$Y*|O8\*z0Deleting
|pM5Zc5J9m0Filehandles and I/O51Testing软件测试网3[2U?q_m"{4q
<STDIN> and <>51Testing软件测试网n|V0NN(} DQ$BP.]
Make Your Own Filehandles
/d.X"bP6G#R0Chopping
1Z:x9]aq.[4F0Printing to Filehandles
mB(pW8o0o'O:|k0Handling File Errors
.Y\$wNaqN0File Tests51Testing软件测试网a:f;^%zS)iJD{
Pipes51Testing软件测试网\UIjso nl
Regular Expressions51Testing软件测试网7`)}3Y\M!Ok
Examples51Testing软件测试网Ril/y7Uz@.Z
Using the Matching Operator51Testing软件测试网d0} v Y3pE0q&{v
Case Insensitivity51Testing软件测试网p!z3_j-n*w.Pc.wV`:_
The Magic of Parentheses
b%tE$U y%p5aj0Substitution
#H G[~-}_}0split() and join()
W+OV i/sW/g3}k!C0Functions
]R PF'i4A0&calling(them)51Testing软件测试网9yka!b2wAOO5};M
my() oh my()
iP B@E/g^:n,z6Q0Special Sort Functions51Testing软件测试网,iU4zs/\J {5`KF
Formats
Introduction
Perl stands for Practical Extraction and Report Language, or Pathologically Eclectic Rubbish Lister. Perl is a very useful programming language that is standard on almost all Unix systems. Its semantics are a lot like C, but its text processing and regular expression matching features are far more powerful. Perl is the ideal tool for the lazy programmer; almost any simple task can be performed using a Perl scrīpt that can be written in under 10 minutes. Perl is particularly powerful for scanning large quantities of text and doing pattern matching. Perl is also very useful as a scrīpting language for web pages (as CGI).
Invocation and #!
To create a Perl scrīpt, simply put your program into a text file. You can invoke it several ways:
1) Execute it from the command prompt withperl -w <file>
2) Put#!/usr/local/bin/perl –w at the top of your scrīpt, make the scrīpt executable, and invoke it simply by typing the scrīpt name at the command prompt. (You still have to type the path to the scrīpt, or if the scrīpt is in the current directory, type./scrīptname.
Tip: You’ll need to make the permissions on the scrīpt executable to run it this way; to do so type:
chmod 700 scrīptname
Basic Semantics
In Perl, comments start with a # and continue to the end of the line. Otherwise, the semantics are basically very similar to C: all statements end with a semicolon; whitespace is ignored; curly braces are used for control structures; functions have arguments in parentheses following the function name.
Hello, World
Pioneered by Brian Kernighan, the Hello, world program is the traditional way to start off a new language. One of the nicest features of Perl, unlike C, is that to do something very simple requires only a very simple scrīpt. You can just go ahead and say:
#!/usr/local/bin/perl -w
# My first perl program
print "Hello, world!\n";
Scalars
Unlike C, Perl does not have separate data types for numbers, characters, strings, and so on. Instead, Perl has three primary data types: scalars, lists, and hashes. Scalars can hold one of several kinds of data:
Type Example(s)
Integers 3