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

Why are you suggesting File::Find? It recurses (unless you kludge it), which is not what the OP wants, and it does not help at all with checking file metadata, which is what the OP needs.

Makeshifts last the longest.

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

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

    Because using File::File::name gets you a file name including the path so that -M or stat can find the file. If you don't want to recurse into directories use:

    if (-d Find::File:name) { File::Find::prune = 1; return; }

    Perl is Huffman encoded by design.

      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.

        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.