(stat "$DirPath/$File")[9] < time() - 180 | [reply] [d/l] |
From "Programming Perl" page 100 (in my edition):
To reset the script's start time to the current time, say this:
$^T = time;
| [reply] [d/l] |
A completely different comment - hope its okay. What is the if(scalar(@Files) > 1) supposed to do? You're skipping all directories with just one entry, which one you skip depends on the file system.
| [reply] [d/l] |
"All directories"? There's only one. "which one you skip depends on the file system."? That makes no sense. If there's only one, how can you choose from many, and how can the result of that choice depend on the file system.
| [reply] |
What I mean is: all directories you run this script on that only contains one directory entry (besides current and parent dir) will not be processed.
Sorry for being imprecise, but I believe my comment still applies. (Updated. Sigh!)
| [reply] |
if(scalar(@Files) > 1)
I agree that this code seems strange, and I will attempt to explain my reason with a concrete example.
The OP is looking at files in a single directory, $DirPath = "/tmp//testing"; (those double slashes look a little messy, but let's ignore that). Let's assume that the directory contains exactly 3 items the first time through the while loop: the 2 special dot directories (. and ..) and 1 file named foo.txt. The readdir will return a list of 3 items, and the grep will filter out the 2 directories. Thus, the @Files array will contain 1 item (the file foo.txt).
Since scalar(@Files) resolves to 1, which is not greater than 1, the code enters the else clause and sleep's for 10 seconds.
Therefore, there is no -M check on the foo.txt file during the first pass through the while loop
because it is the only file in the directory. I doubt that is what the OP really wants.
In fact, there will be no -M checks until there are at least 2 files in the directory, no matter how many 10 second intervals (and times throught the loop) elapse.
Perhaps the OP has never encountered this corner case because there are always at least 2 files in the directory. Or maybe the OP just does not care about this case. But, it does seem strange to me. To avoid this corner case, if(scalar(@Files) > 0) could be used (or, more simply if(@Files)).
Another reason the OP may never notice this case is if the directory contains at least 1 subdirectory. For example, if $DirPath contains a directory 'bar' in addition to file foo.txt, then the @Files array will contain 2 items (bar and foo.txt) after the grep/readdir. In this case, if(scalar(@Files) > 1) would be true, and the -M check would be preformed on the foo.txt file, but just as a happy accident. Again, I doubt that is what the OP really wants.
If it were my code, I would filter out all directories with grep, not just the 2 special dot directories:
my @Files = grep { -f "$DirPath/$_" } readdir DIR;
| [reply] [d/l] [select] |
| [reply] |