perl入门网站和几个好玩的地方
http://www.cbi.pku.edu.cn/chinese/documents/perl/index.htm
--------------------------
.双引号内的字符串中支持转义字符
Table 3.1. Escape sequences in strings.
Escape SequenceDescription
\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关闭掉,如:
$a = "T\LHIS IS A \ESTRING"; # same as "This is a STRING"
------------------------
列表/数组的长度
当数组变量出现在预期简单变量出现的地方,则PERL解释器取其长度。
@array = (1, 2, 3);
$scalar = @array; # $scalar = 3,即@array的长度
($scalar) = @array; # $scalar = 1,即@array第一个元素的值
注:以数组的长度为循环次数可如下编程:
$count = 1;
while ($count <= @array) {
print ("element $count: $array[$count-1]\n");
$count++;
}
-------------------------------
@array = (70, 100, 8);@array = sort(@array); # @array = (100, 70, 8) now@array2 = reverse(@array);@array2 = reverse sort (@array);chop--数组去尾join/split--连接/拆分
文件测试操作符操作符描述-b 是否为块设备-c 是否为字符设备-d 是否为目录-e 是否存在-f 是否为普通文件-g 是否设置了setgid位-k 是否设置了sticky位-l 是否为符号链接-o 是否拥有该文件-p 是否为管道-r 是否可读-s 是否非空-t 是否表示终端-u 是否设置了setuid位-w 是否可写-x 是否可执行-z 是否为空文件-A 距上次访问多长时间-B 是否为二进制文件-C 距上次访问文件的inode多长时间-M 距上次修改多长时间-O 是否只为“真正的用户”所拥有-R 是否只有“真正的用户”可读-S 是否为socket-T 是否为文本文件-W 是否只有"真正的用户"可写-X 是否只有"真正的用户"可执行注:“真正的用户”指登录时指定的userid,与当前进程用户ID相对,命令suid可以改变有效用户ID。
1、用&调用 &subname; ... sub subname{ ... }2、先定义后调用 ,可以省略&符号 sub subname{ ... } ... subname;3、前向引用 ,先定义子程序名,后面再定义子程序体 sub subname; ... subname; ... sub subname{ ... }4、用do调用 do my_sub(1, 2, 3);等价于&my_sub(1, 2, 3);