in reply to Finding Oldest File in a Directory

$file =~ /BOT/ will never succeed because readdir returns the leaf name, not the whole path so you get BOT rather than /www/htdocs/reports/bot/.

For something like this I'd be inclined to use File::Find in any case.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: Finding Oldest File in a Directory
by Aristotle (Chancellor) on Oct 08, 2005 at 19:19 UTC

    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.

      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.