[Omaha.pm] Help with File::Find
Mike Hostetler
hostetlerm at gmail.com
Thu Nov 6 12:11:35 PST 2008
On Thu, Nov 6, 2008 at 1:31 PM, Jay Hannah <jay at 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20081106/75d72dce/attachment.html>
More information about the Omaha-pm
mailing list