You could make an array of files and one of timestamps with fixed size, and use those to hold the newest files and timestamps, unshifting, popping and splicing:
#!/usr/bin/perl use File::Find; use strict; die "usage: $0 n dir [dir ...]\nwhere n is number of items to report\n +" unless @ARGV; my $n = (shift) - 1; my @d = @ARGV; my @f; my @t; $#f = $n; # preallocate $n elements $#t = $n; # for these arrays find(\&wanted, @d); print join("\n", map { scalar(localtime((stat $_)[9])) . " $_" } @f ),"\n"; sub wanted { my $file = $File::Find::name; return if -d $file; my $time = (stat($file))[9]; # mtime # if file is newer or as new than the first file... if ($t[0] < $time) { unshift @t, $time; unshift @f, $file; pop @t, pop @f if $#t > $n; return; } # ...else insert the found file in the list. for( my $i = 1; $i<= $#t; $i++) { if($time >= $t[$i]) { # oops splice @t,$i,1, $time; # oops splice @f,$i,1, $file; splice @t,$i,0, $time; splice @f,$i,0, $file; pop @t, pop @f if $#t > $n; return; } } }

SkipHuffman++ - seems like I needed that utility :-)

update: it has to be splice @t,$i,0, $time; certainly, not 1 ...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: How can I access a cross directory set of data files by most recently modified date? by shmem
in thread How can I access a cross directory set of data files by most recently modified date? by SkipHuffman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.