|Welcome to the Monastery|
Oldest file using -Mby Gerard (Pilgrim)
|on Apr 27, 2004 at 05:18 UTC||Need Help??|
Gerard has asked for the wisdom of the Perl Monks concerning the following question:
Greetings fellow monks
I am trying to find the oldest file in a directory, am running win 2000, apache 1.3. I have the following sub.
Which I gleamed from another post here at the monastery. When running this a lot of times in quick succession with files being created and removed in between (but not at the same time), about one time in 10 this will break, not returning any value (when there are definitely files in the directory). Perplexed I have changed the line my $oldest_age = 0; to my $oldest_age = -1; Thinking that possibly the $age could be = 0 when there is only one file....This seems to have helped a lot, reducing the number of "breaks" down to about 1 in 100, but there are still multiple files in the directory. (In my tests, 5 and 8).
It is possible that the calling code is broken, but I can't see anything obvious. Here is that sub in case that helps
This now runs most of the time, but not all the time... It dies when trying to check the file size, as $filename doesn't contain anything.
Any ideas on what I am doing wrong, and what exactly -M file contains. To be honest I was surprised that changing it to -1 helped, but I changed it back to 0 just to check, and sure enough the problem occured a lot more frequently. Help?