第十一章:文件测试

上一篇 / 下一篇  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:

 

评分:0

我来说两句

日历

« 2024-04-30  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 47867
  • 日志数: 80
  • 建立时间: 2008-10-27
  • 更新时间: 2009-07-17

RSS订阅

Open Toolbar