[Omaha.pm] Help with File::Find
Mike Hostetler
hostetlerm at gmail.com
Thu Nov 6 05:50:20 PST 2008
I knew I should have added it. This is my complete subroutine:
sub getLogFiles {
my ($logdir,$proc) = @_;
my @logfilelist =();
my @files=();
sub myLogs {
/^$proc.*/s
&& push(@files,$File::File::name);
}
find(\&myLogs,$logdir);
my $filestats={};
my $latesttime=0;
my $myfile="";
foreach (@files) {
$filestats=stat($_);
if ($filestats->mtime>$latesttime) {
$myfile=$_;
$latesttime=$filestats->mtime;
}
}
push(@logfilelist,$myfile);
return @logfilelist;
}
My pain is that I want to get the newest file, and the only way I could
think of is to add all the files that I want onto a list and compare them.
File::Find requires a subroutine, so I made it a nested subroutine, thinking
that it would be treated as local..Alas, I learned that Perl doesn' t work
like that but still, in theory, this should. But it doesnt . . .
On Wed, Nov 5, 2008 at 6:06 PM, Andy Lester <andy at petdance.com> wrote:
>
> On Nov 5, 2008, at 3:50 PM, Mike Hostetler wrote:
>
> sub logFinder {
>> my $proc="pat"
>> my @files=();
>>
>> sub wanted {
>> /^$proc.*/s
>> && push(@files,$File::File::name);
>> }
>>
>> find(\&wanted ,$logdir);
>>
>
>
> First, there's no need to match /^$proc.*/, because it is the same as
> /^$proc/.
>
> I think something is missing here. Is wanted() inside of logFinder? Why?
> Perl doesn't nest subs like that.
>
> Can you show us an entire program?
>
> xoa
>
>
> --
> Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance
>
>
>
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm at pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>
--
Mike Hostetler
http://mike.hostetlerhome.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20081106/41791bbb/attachment.html>
More information about the Omaha-pm
mailing list