[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Help with File::Find



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@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@petdance.com => www.petdance.com => AIM:petdance




_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm



--
Mike Hostetler
http://mike.hostetlerhome.com/