in reply to Re^2: how to list the files in dir with respect to time
in thread how to list the files in dir with respect to time
I was confused too why zaxo said it will reduce number of stat calls. I am yet to familiarize myself with ST so i will read up on that before I ask any questions regarding that :)
Seems like the OP wanted the last modified file. So why store all file and then sort instead of a simple max?
Modifying graff's code here
Update : Added logic to update $max. Thanks graff. my oversight.
my %file_date; my $max = -99999999; # set it to first file's mtime would be better # but just for demonstration here my $mtime; my $file; for ( glob '/path/to/*.log' ) { $mtime = (stat)[9]; if ($max <= $mtime) { $file = $_; $max = $mtime; } print ("file = $file\n"); # my $newest = ( sort { $file_date{$b} <=> $file_date{$a} } keys %file +_age )[0];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: how to list the files in dir with respect to time
by graff (Chancellor) on Aug 02, 2005 at 03:44 UTC | |
by sk (Curate) on Aug 02, 2005 at 03:46 UTC |