第十一章:文件测试
上一篇 /
下一篇 2008-11-12 11:37:13
/ 个人分类:《Perl语言入门》-小骆驼书-练习题答案
1)
use warnings;
foreach(@ARGV){
if (-e){ # -e means -e $_
print "$_ exists.\n";
} else{
print "$_ Not exists.\n";
}
if (-r){
print "$_ is readable.\n";
} else{
print "$_ is Not readable.\n";
}
if (-w){
print "$_ is writable.\n";
} else{
print "$_ is Not writable.\n";
}
if (-x){
print "$_ is executable.\n";
} else{
print "$_ is Not executable.\n";
}
}
2)
use warnings;
die "No file names supplied!\n" unless @ARGV;
my @files;
my $oldest;
my $days;
foreach(@ARGV){
if(-e){
push @files, $_;
}
}
foreach(@files){
$days = -M;
$oldest = $_ if $oldest < $days;
}
printf "The oldest file was %s, and it was %.f days old.\n", $oldest, $days;
收藏
举报
TAG: