写个perl程序,从命令行参数指定的文件列表中找出最旧的文件,并汇报其存在了多少天。
- #! /usr/bin/perl
- sub max {
- my $max = push @_;
- foreach (@_) {
- $max = $_
- if $max < $_;
- }
- return $max;
- }
- my @list = @ARGV;
- if (! @list) {
- print "Please choose somefiles!\n";
- } else {
- my %mt;
- foreach (@list) {
- if ( -f $_ || -d $_ ) {
- $mt{$_} = -M $_;
- } else {
- print "There is no such file or director which names $_\n"
- }
- }
- my $oldert = &max(values %mt);
- my %tm = reverse %mt;
- print "the file $tm{$oldert} is the oldest, and it already $oldert days\n";
- }
编辑回复