[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] Help with File::Find
On Thu, Nov 6, 2008 at 1:31 PM, Jay Hannah <jay@jays.net> wrote:
Does this help?
$ find ./ -name "pat*" | xargs ls -at | head -1
It's ironic that you put that, since that's pretty much the exact command I'm replacing. :) The problem is that one some of these systems "ls" is aliases to always put filesize in front (why? I don't know -- I find it annoying).
This is what I came up with after some googling and piecemailing. Anonymous subroutines are a good thing!
sub getLogFiles {
my ($logdir,$proc) = @_;
my @logfilelist =();
my %files={};
find(
sub {
if (/^$proc/s) {
my $filestats=stat($File::Find::name);
$files{$File::Find::name}=$filestats->mtime;
}
},$logdir);
my $myfile= (sort{ $files{$a}<=>$files{$b} } keys %files)[-1];
return $myfile;
}
--
Mike Hostetler
http://mike.hostetlerhome.com/