• 博客访问： 54865
• 博文数量： 23
• 博客积分： 1598
• 博客等级： 上尉
• 技术积分： 210
• 用 户 组： 普通用户
• 注册时间： 2010-08-27 10:26

2011年（2）

2010年（21）

2010-09-19 15:32:44

Perl

## 数据定义与使用

PERL最常用的简单变量，由于其与其它语言基本相同，不再赘述。例：

```\$x = 12345;
if (1217 + 116 == 1333) {
# statement block goes here
}```

8进制以0打头，16进制以0x打头。例：

```\$var1 = 047;# (等于十进制的39)
\$var2 = 0x1f;# (等于十进制的31)```

```#!/usr/local/bin/perl
\$value = 9.01e+21 + 0.01 - 9.01e+21;
("first value is ", \$value, "\n");
\$value = 9.01e+21 - 9.01e+21 + 0.01;
("second value is ", \$value, "\n");
#---------------------------------------------------------
#\$program3_3
#first value is 0
#second value is 0.01```

```\$number = 11;
\$text = "This text contains the number \$number.";
#则\$text的内容为："This text contains the number 11."```

Table Escape sequences in strings.

Escape SequenceDescription
\aBell (beep)
\bBackspace
\cnThe Ctrl+n character
\eEscape
\EEnds the effect of \L, \U or \Q
\fForm feed
\lForces the next letter into lowercase
\LAll following letters are lowercase
\nNewline
\rCarriage return
\QDo not look for special pattern characters
\tTab
\uForce next letter into uppercase
\UAll following letters are uppercase
\vVertical tab

\L、\U、\Q功能可以由\E关闭掉，如：
\$a = “T\LHIS IS A \ESTRING”; # same as “This is a STRING”

```\$res = "A quote \" and A backslash \\";
\$result = 14;
("The value of \\$result is \$result.\n")的结果为：
The value of \$result is 14.```

```\$result = "\377"; # this is the character 255,or EOF
\$result = "\xff"; # this is also 255```

```\$text = 'This is two
lines of text
';
#与下句等效：
\$text = "This is two\nlines of text\n";```

```\$string = "43";
\$number = 28;
\$result = \$string + \$number; # \$result = 71
#若字符串中含有非数字的字符，则从左起至第一个非数字的字符，如：
\$result = "hello" * 5; # \$result = 0
\$result = "12a34" +1; # \$result = 13```