#!/usr/bin/perl -w
######################################################################
# latest.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use File::Find;

foreach $arg (@ARGV) {            # cycle through all
    File::Find::find(\&fc, $arg); # specified directories
}                                 # and build %Filesbydate

$maxcount = 10;                   # output max. 10 files

                                  # evaluation: sort
                                  # by last date
hashloop:foreach $date (sort { $b <=> $a } keys %Filesbydate) {

                                  # lists of entries
    $timestr = localtime($date);  # of same date

    foreach $file (@{$Filesbydate{$date}}) {
        print "$file (", $timestr, ")\n";        # output with date
        last hashloop unless $maxcount--;        # terminate when enough
    }
}

#################################################################
# Callback function of File::Find::find
#################################################################
sub fc {
    my $filedate = (stat($_))[9]; # last modification date

    return unless -f _;           # no directories, economical
                                  # stat() call

                                  # date not yet occupied:
                                  # new array reference
    $Filesbydate{$filedate} = [] unless
                                exists $Filesbydate{$filedate};

                                  # include entry in array
    push(@{$Filesbydate{$filedate}}, "$File::Find::dir/$_");
}

