It was just an attempt to see how someone else may tackle this issue. I thought of sorting, but I wasn't sure it will do exactly what I expect. Here is what I've have so far:
my $dir = "/mydir";
opendir(DH, "$dir") || die "Failed to open $dir: $!\n";
my $counter = 0; while (defined(my $file = readdir (DH))){ next if $file =~ /^\.+$/; push @files, $file; $counter++;
} closedir (DH);
if ($counter > 7){
for (@files){ $file_mtime{$_} = (stat($_))[9];
Need to compare mtime here... } }
You don't need to sort, you can do it like this:
my $dir = '/mydir';
opendir DH, $dir or die "Failed to open $dir: $!\n";
my $time = ~0; # set $time to a very large number my $name;
while ( my $file = readdir DH ) {
-f "$dir/$file" and $time > -M _ and ( $name, $time ) = ( "$dir/$file", -M _ )
}
print "The newest file is $name.\n";
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>