您的位置:首页 > 其它

perl 1-3 chapter

2016-03-04 00:43 302 查看
Basic Perl Programming (practical extraction and report language)
designed by Larry Wall
recored by ericxlin @.@

第一章 简介


第二章 简单变量
----整数
----浮点数
----字符串
················start
----整型
perl将整数存在浮点寄存器中
八进制 0打头 十六进制 0x
----浮点数
浮点寄存器通常不能精确存贮浮点数,从而产生误差,指数范围 -309 ~ +308
----字符串
注意:在perl中,字符串的末尾不含有隐含的NULL字符
双引号支持:简单变量替换,转义字符
Escape Sequence Description
\a Bell (beep)
\b Backspace
\cn The Ctrl+n character
\e Escape
\E Ends the effect of \L, \U or \Q
\f Form feed
\l Forces the next letter into lowercase
\L All following letters are lowercase
\n Newline
\r Carriage return
\Q Do not look for special pattern characters
\t Tab
\u Force next letter into uppercase
\U All following letters are uppercase
\v Vertical tab
\L \U \Q 功能可以由 \E 关闭
双引号中:反斜线 \" \\ \$ 取消变量替换
双引号中:可用\nnn 或 \xnn 表示ASCII字符
单引号字符串
----单引号 没有变量替换功能;反斜线不支持转义字符,而只在包含单引号和反斜线是起作用;可以跨多行。
字符串和数字的转换
变量初始值
----缺省初始值为空字符""
················end

第三章 操作符
1----算术操作符
2----整数比较操作符
3----字符串比较操作符
4----逻辑操作符
5----位操作符
6----赋值操作符
7----自增自减操作符
8----字符串联结和重复操作符
9----逗号操作符
10----条件操作符
11----操作符的次序
················start
1----算术操作符
+ - * / **(乘幂) %(取余)-(单目负)
**的基数不能为负;**不能溢出;
2----整数比较操作符
< > == <= >= !=
<=> 比较,返回 1, 0, or -1
<=>结果为:
0 --> 相等
1 --> 第一个值大
-1 --> 第二个值大
3----字符串比较操作符
lt gt eq le ge ne 
cmp 比较,返回 1, 0, or -1
4----逻辑操作符
与: && 或 and
或: || 或 or
非: ! 或 not
异或: xor
5----位操作符
与:&
或:|
非:~
异或:^
左移: <<
右移: >>
注:不要将&用于负整数,因为PERL将会把它们转化为无符号数。
6----赋值操作符
操作符 描述
= Assignment only
+= Addition and assignment
-= Subtraction and assignment
*= Multiplication and assignment
/= Division and assignment
%= Remainder and assignment
**= Exponentiation and assignment
&= Bitwise AND and assignment
|= Bitwise OR and assignment
^= Bitwise XOR and assignment
7----自增自减操作符
++ --
不要在变量自增/自减后在同一表达式中再次使用
在perl中++可用于字符串,但在结尾字符为'z' 'Z' '9'时进位
不要使用--,perl会先将字符串转换为数字再进行自减
如果字符串中含有非字母且非数字的字符,或数字位于字母中,则经过++运算前面的值转换为数字零,因此结果为1
8----字符串联结和重复操作符
联结 .
重复 x
联结且赋值(类似+=) .=
9----逗号操作符
提高程序的可读性,将关系密切的两个表达式结合在一起
10----条件操作符
条件?值1:值2
当条件为真时取 值1,为假时取 值2
在perl 5 中,还可以在赋值式左边使用条件操作符来选择被赋值的变量
11----操作符的次序
操作符 描述
++, -- 自增,自减
-, ~, ! 单目
** 乘方
=~, !~ 模式匹配 !!!
*, /, %, x 乘,除,取余,重复 !!!
+, -, . 加,减,联接 !!!
<<, >> 移位
-e, -r, etc. 文件状态 !!!
<, <=, >, >=, lt, le, gt, ge 不等比较
==, !=, <=>, eq, ne, cmp 相等比较 !!!
& 位与
|, ^ 位或,位异或
&& 逻辑与
|| 逻辑或
.. 列表范围 !!!
? and : 条件操作符
=, +=, -=, *=, 赋值
and so on  
, 逗号操作符
not Low-precedence logical NOT
and Low-precedence logical AND
or, xor Low-precedence logical OR and XOR
操作符结合性(associativity):
操作符 结合性
++, -- 无
-, ~, ! Right-to-left !!!
** Right-to-left !!!
=~, !~ Left-to-right
*, /, %, x Left-to-right
+, -, . Left-to-right
<<, >> Left-to-right
-e, -r, 无
<, <=, >, >=, lt, le, gt, ge Left-to-right
==, !=, <=>, eq, ne, cmp Left-to-right
& Left-to-right
|, ^ Left-to-right
&& Left-to-right
|| Left-to-right
.. Left-to-right
? and : Right-to-left !!!
=, +=, -=, *=, Right-to-left !!!
and so on  
, Left-to-right
not Left-to-right
and Left-to-right
or, xor Left-to-right
建议:当不确定某操作符是否先执行时,一定要用括号明确之。
用多行,空格等方式提高程序的可读性。
················end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: