http://ind.ntou.edu.tw/~dada/cgi/Perlsynx.htm
my 是一種宣告變數的方式,它可以使變數區域化。
宣告變數時若不加 my 或 local 則Perl會把它當作全域變數使用。
習慣上,我們會將字串用雙引號括起來,而數值就不用加引號。
字符串运算符和函数:
函数(算子) | 意义 |
---|---|
(str) x (int) | 字符串的重复叠加,类比 py 的 “str”*2 == “strstr” |
(str).(str) | 字符串链接运算 |
eq,ne | 相等,不等;返回 T/F。 $x == $y compares two numbers for equality, and $x eq $y compares two strings. |
cmp | Returns -1, 0, or 1 if the left operand is stringwise less than, equal to, or greater than the right operand. |
数值运算符和函数:
函数(算子) | 意义 |
---|---|
< = > | Returns -1 if the left operand is less than the right, +1 if is it greater than, and 0(False) otherwise. |
符号规约
(算子) | 意义 |
---|---|
<> and while(<>) | is explained in perlop (the latter is also explained in perlvar). <> is called the “null file handle”. It is a special construct and does not just mean <STDIN> |
~~ smart matching operator | 见引用一 |
引用一
perl智能匹配操作符~~
What’s the use of <> in Perl?
%a ~~ %b 哈希的键是否一致
%a ~~ @b 至少%a中的一个键在列表@b之中
%a ~~ /Fred/ 至少一个键匹配给定的模式
%a ~~ 'Fred' 哈希中某一指定键$a{Fred}是否存在
@a ~~ @b 数组是否相同
@a ~~ /Fred/ 至少有一个元素匹配给定的模式
@a ~~ 123 至少有一个元素转化为数字后是123
@a ~~ 'Fred' 至少有一个元素转化为字符串后是'Fred'
$name ~~ undef $name确实尚未定义