Well it's 3:00 AM on Monday for me but I see a recent post so here is some code that ought to give you a lot of ideas. It sorts by atime and I think ought to have enough commented out print statements to help understand what is going on.
PS: I really recommend the "use strict;" line in there. I put it in every perl program I write. See strict for more info.
Update: added @lowest_ten_times to show how to get the lowest 10 times.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $directory = "/home/frink/code/perl/z/";
opendir DIR, $directory;
my @file_names = readdir DIR;
closedir DIR;
# remove "." and ".."
@file_names = grep {!/^\.$/} @file_names;
@file_names = grep {!/^\.\.$/} @file_names;
# add the full path name back on (used by "stat()" below.)
@file_names = map {$_ = $directory . $_} @file_names;
# print "file_names: " . Dumper(\@file_names);
my %times_to_names;
foreach my $name (@file_names) {
my $atime = (stat($name))[8];
$times_to_names{$atime} = $name;
# print "file: $name\t";
# print "atime: $atime\t";
# print "\n";
}
# print "times_to_names: " . Dumper(\%times_to_names);
my @times_sorted = sort(keys(%times_to_names));
# print "times_sorted: " . Dumper(\@times_sorted);
foreach my $time (@times_sorted) {
print $time . "\t" . $times_to_names{$time} . "\n";
}
my @lowest_ten_times = @times_sorted[0..9];
# print "lowest_ten_times: " . Dumper(\@lowest_ten_times);
|