#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |