获取当期目录 :
use Cwd;
my $dir = getcwd;
数组操作:
1)push(@array,element);#在数组尾新添一个元素
2)$ele = pop(@array);#数组尾弹出一个元素
3)$ele = shift(@array);#数组开头弹出一个元素
4)unshift(@array,$element);#数组开头插入一个元素。
遍历文件夹:
opendir DH,$dir or die 'xxxx';
foreach(readdir(DH)){
next if($_ eq '.' || $_ eq '..' || $_ eq '.svn');
my $file = $dir . "/" . $_;
if(!-l $file && -d _){
xxxx;
}
}
Preg 中插入变量
$a = "temp";
/^$a.*/ 匹配以temp开头字符串
数组正则匹配操作
@list = grep(pattern,@input);#@list 为@input 中匹配patter 的元素集合
DATA:DUMPER 用法:
-
use Data::Dumper;
-
print Dumper($var);
Perl get opt :
-
use Getopt::Long;
-
use vars qw($opta $optb $optc);
-
GetOptions(
-
"a=s" => \$opta,#'s' 表示字符串参数
-
"b|opt-b:i" => \$optb,#长短参数,'i'表示整数
-
"c" => \$optc #"-c" 为“0”or "1"参数
-
)
UTF8 与GBK 转换
-
use Encode;
-
-
my $gbk = encode("gb2312","sxfsfaf");#utf8 --> gbk
-
-
my $utf = encode("utf-8",decode("gbk",$gbk));#gbk -> utf8
-
-
$gbk = encode("gb2312",decode("utf8",$utf));#utf8 -> gbk
-
$utf = encode_utf8(decode("gbk",$gbk));#gbk -> utf8
文件拷贝、移动、重命名
-
use File::Copy;
-
-
copy($src,$des) or warn "Fail to copy : $!";
-
-
move($src,$des_dir);
-
-
rename($src,$des);
创建/删除路径:
-
use File::Path qw(make_path,remove_tree);
-
-
make_path("xxxx");///just like "mkdir -p"
-
remove_tree("xxxx");///just like "rm -r"
阅读(694) | 评论(0) | 转发(0) |