写一个perl程序找到给定文件列表中最老的文件

回复 收藏
写个perl程序,从命令行参数指定的文件列表中找出最旧的文件,并汇报其存在了多少天。
  1. #! /usr/bin/perl
  2. sub max {
  3.         my $max = push @_;
  4.         foreach (@_) {
  5.                 $max = $_
  6.                         if $max < $_;
  7.         }
  8.         return $max;
  9. }
  10. my @list = @ARGV;
  11. if (! @list) {
  12.         print "Please choose somefiles!\n";
  13. } else {
  14.         my %mt;
  15.         foreach (@list) {
  16.                 if ( -f $_ || -d $_ ) {
  17.                         $mt{$_} = -M $_;
  18.                 } else {
  19.                         print "There is no such file or director which names $_\n"
  20.                 }
  21.         }
  22.         my $oldert = &max(values %mt);
  23.         my %tm = reverse %mt;
  24.         print "the file $tm{$oldert} is the oldest, and it already $oldert days\n";
  25. }
2012-12-28 16:36 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: