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

Instead of just prepending the path to the filename? I would consider that almost obfuscatory, besides the fact that it’s about 4× more work to write and ends up a lot slower to boot.

Makeshifts last the longest.

  • Comment on Re^4: Finding Oldest File in a Directory

Replies are listed 'Best First'.
Re^5: Finding Oldest File in a Directory
by GrandFather (Saint) on Oct 08, 2005 at 21:35 UTC

    Slower certinally, OP's fixed code is about 3x faster than using similar File::Find code.

    Rate FileFind FixedOP FileFind 163/s -- -70% FixedOP 546/s 235% --

    4x more work? Well 19 lines versus 19 lines doesn't look like 4x more work to me (I did change formating to my style, but even using K&R the difference is not great - 16 versus 17).

    Actually, in my initial answer to you I should also have said: "To make the OP, and any others reading this thread for enlightenment, aware of another way to do it.

    I'm sure that OP fixed his problem using the information in the first part of my node or the same information from one of the other replies. However if he finds that he needs to search a list of directories or sub-directories, OP is now aware of a tool that will make that easier.


    Perl is Huffman encoded by design.

      Well, if you want to make a meaningful comparison then you need to rewrite the OP’s code such that it follows your F::F code’s style. The resulting loop body is half as long as the one which has to handle $File::Find::prune. But I didn’t consider that that gets lost in the extra setup/teardown for the readdir code.

      Nevertheless I stand by my opinion that using F::F for this purpose shrouds the intent; even more so now that I’ve actually seen the working code on screen. (What with . being another unrelated case to handle.) The readdir code OTOH is straightforward.

      As for the performance, that was actually the last of my concerns (take note of the order of arguments). I just mentioned it to say that I see no metric by which this approach might be preferrable: not clarity; not brevity; not even speed if nothing else.