I'm reading a number of daily log files and displaying their contents. The log entries in the files are ordered by date no problem. However I would like the files to be ordered on my page so that the most recent appears at the top. When reading the filesnames from the directory using readdir is there some way of sorting the results by the last modified date on the file?
This is what I have so far:
# Open directory handle for log directory
opendir(DIR, "log") || print "open dir error: $!";
# Read the log files in the directory into array
@files = grep( /\.log$/i , readdir( DIR) );
foreach $file(@files)
{
# Print log file name
print "<h3>$file</h3>\n";
~(stat)[9] doesn't appear to be working. It returns 0 for each file. I'm afraid I don't understand the ~ Does it call stat with the last value of $_ ? If so then I don't think its working. Do you need 'use' something use this form?
Almost there, your solution works if I use
map{sprintf"%8x %s",(stat(_$))[9],$_}
but obviously I don't get the filename in the second field.
Many Thanks,
Andy.
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.