http://www.perlmonks.org?node_id=498479


in reply to Re^2: Finding Oldest File in a Directory
in thread Finding Oldest File in a Directory

It has been a while since i posted this - I think i looked at the OP's readdir() and somehow felt he is doing some kind of recursion as for just checking the oldest file in a directory can be accomplished using glob or just use the Plain Old Shell and call the script with a * (check for -d etc.) or ls -lrt

That said, I agree File::Find might not be the best way to solve this problem but it can be used to achieve what the OP wants as GrandFather has shown or just eval finddepth and die on finding a directory as finddepth works bottoms-up.

I just find it much easier to use File::Find and it is very easy to expand (if recursion is ever required).

I am not worried too much about performance in this case even if it is 4X times slower. How many times do i have to remove the oldest file? Am i working with 1000s of files? etc. The OP has not mentioned anything about perormance so i am presuming that arg is not very important.

I definitely DO NOT disagree with your comment(s). It is my mistake not noticing that OP did not ask for recursion, I will update my node saying it does recursion and it is upto the OP to choose it or not.

cheers

SK