Keep It Simple, Stupid | |
PerlMonks |
Re: Onliner magic to remove filesby Anonymous Monk |
on Dec 24, 2014 at 01:14 UTC ( [id://1111262]=note: print w/replies, xml ) | Need Help?? |
for(<*>){((stat)[9]<(unlink))} The apparently useless stat and < made me a bit curious, so I googled it a bit. There are several places where the above is presented as a one-liner for "fast file deletion", but without explaining what the stat might be for. Several people claimed that the Perl solution is faster than find with the -delete option, and I found one (possibly dubious) claim that it's because find uses fstatat64 syscalls while Perl uses lstat64+stat64 syscalls (a quick check on my system appears to confirm this). However, since it isn't my area of expertise, I'm not sure if that causes a speed difference. In a post by Kent Fredric - https://www.quora.com/Linux-why-stat+unlink-can-be-faster-than-a-single-unlink - he shows that removing the stat actually gives a minor performance improvement, so I suspect it really isn't necessary. My best guess for now is that the code snippet is a bastardization of something like this, and it's just been cargo-culted from there.
In Section
Seekers of Perl Wisdom
|
|