perl点滴知识
1.实现lpad函数#append with blank before the str
sub lpad{
my $str = shift;
my $length= shift;
$str=" ".$str until ($length-- == 0) ;
return $str;
}
2.实现trim函数
#trim, remove blank from the start and end of string
sub trim{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
3.数据排序
@output_array=sort { $a-> <=> $b-> } @output_array;
@output_array=sort { $a-> <=> $b-> } @output_array;
4.二维数组
@temp;
@sub_temp=(1,2,3);
$temp=[@sub_temp];
5.unlink删除
if(-e $output_dir){
print LOG ("xxxxxxx,"\n");
unlink $output_dir;
}
6.按\s+分隔字符串
perl按\s+分割字符串 得到每段完整的空白字符串和非空白字符串(包括空格,回车,tab等)
比如:
$str="123 456 789 ";
得到
@a=("123"," ",567," ","789"," ");
7.perl 多行注释
单行用#
多行如下(将注释的内容放在=pod和=cut之间):
=pod
xxx
xxx
=cut
页:
[1]