I worked on a script that would recursively search the file system and delete any file (without directories) that is older than 20 days. I used the command find2perl(which is part of File :: Find ), and that was the result. (I noticed that he does not understand the parameter -delete, so I had to use the old -exec...version.)
(parts of the script are truncated)
sub delete_old_files {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
(int(-M _) > 20) &&
unlink($_);
}
I understand the part lstat, checking the file -fand unlink, but I'm not sure how it works (int(-M _) > 20). Obviously, it checks the modified date for 20 days, but I have never seen this syntax before, and I'm curious to understand where it comes from and how it works. I am also interested in how it can refer to an iterator as a simple underscore without using $_for -fand part of the time check.
source
share