in reply to How can I access a cross directory set of data files by most recently modified date?

You can use an array of all files (see File::Find or File::Find::Rule) and sort them by modification time:

@files = sort {(stat $b)[9] <=> (stat $a)[9])} @files;

  • Comment on Re: How can I access a cross directory set of data files by most recently modified date?
  • Download Code

Replies are listed 'Best First'.
Re^2: How can I access a cross directory set of data files by most recently modified date?
by SkipHuffman (Monk) on Jun 07, 2007 at 16:31 UTC

    I thought of that, but it seems kind of brute force for something someone probably has solved more elegantly.

      You can use a schwartzian transform to make it more efficient by only doing the stat call once per file, but other than that there's not that much more to it.

      Update: For those playing along at home that'd be @files = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (stat $_)[9] ] } @files;

      Well, using a binary heap as a data structure might be more efficient, especially if you know you know that you need only the the knewest $k files, then all insertion and deletion operations will be in O(log $k) operations.

      But if you are talking about a more elegant interface: I don't know any :(

        Thanks, that may be the way I need to go, but I would rather not reinvent the square wheel if I don't have to.

        Skip