[b][color=red]检测操作系统的类型[/color][/b]
linux on Linux and MSWin32 on Windows
[url]http://stackoverflow.com/questions/334686/how-can-i-detect-the-operating-system-in-perl[/url]
[b][color=red]取得文件名称[/color][/b]
[b][color=red]删除目录下的文件[/color][/b]
[b][color=red]文件上传[/color][/b]
[color=red][b]去掉字符串两边的空格或回车换行[/b][/color]
[b][color=red]日期格式化[/color][/b]
[url]http://blog.chinaunix.net/uid-608135-id-2948410.html[/url]
print "$^O\n";
linux on Linux and MSWin32 on Windows
use English qw' -no_match_vars ';
print "$OSNAME\n";
use Config;
print "$Config{osname}\n";
print "$Config{archname}\n";
[url]http://stackoverflow.com/questions/334686/how-can-i-detect-the-operating-system-in-perl[/url]
[b][color=red]取得文件名称[/color][/b]
my $fileName = $file; # /tmp/test.log
$fileName =~ s!^.*(\\|\/)!!; # 得到fileName - "test.log"
[b][color=red]删除目录下的文件[/color][/b]
-d $_?rmtree($_):unlink $_ foreach (<data/*>);
[b][color=red]文件上传[/color][/b]
if (!open(OUTFILE, ">$baseDir/$fileName")) {
print "Cannot open the file $baseDir/$fileName";
exit;
}
while (my $bytesRead = read($_, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
[color=red][b]去掉字符串两边的空格或回车换行[/b][/color]
sub trim_str
{
my $str = shift;
if ($$str) {
$$str =~ s/^\s+//g;
$$str =~ s/\s+$//g;
$$str =~ s/[\r\n]//g;
}
return $str;
}
[b][color=red]日期格式化[/color][/b]
use POSIX qw(strftime);
my $time = strftime("%Y%m%d%H%M%S", localtime(time));
[url]http://blog.chinaunix.net/uid-608135-id-2948410.html[/url]