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];
In reply to Re^3: how to list the files in dir with respect to time
by sk
in thread how to list the files in dir with respect to time
by swaroop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |