--- Shawn <[EMAIL PROTECTED]> wrote:
> . . . 
> Is there any better way to gather a bunch of files' stat data than
> looping and calling lstat?
> . . .

Nothing jumps to mind, though I think I can suggest another speed
optimization or two below. 

> sub lookat {
>   my ($entry) = @_;
>   my $name = "lookat";
>   my (@files);
>   return if exists($dirs{$entry});
>   print "\t$name -> traversing $entry\n" if DEBUG & TRAVERSE;

>   $dirs{$entry} = {};

Try:
    my %entry;

later we'll save it back, but for now, we avoid the extra level of
lookups.
 
>   opendir DIR, $entry or die "can't open $entry: $!\n";
>   for (grep !/^\.\.?$/, readdir DIR) {
>     next if exists($ignore{$_}); 
>     my $file = "$entry/$_";
>     $file =~ s!//!/!g;
>     
>     my @stats = ( '0', (lstat $file)[0,1,7,9] );
> 
>     if (-r _ && -f _) {
>       print "\t\t$name -> F $file\n" if DEBUG & REPORT;
>       $dirs{$entry}{$_} = \@stats;
>     }

This is fine, but as a simplification, (just for consideration):

   if (-r _ and $f _) { # I like and better than &&; some differences
        print "\t\t$name -> F $file\n" if DEBUG & REPORT;
        $entry{$_} = [ '0', (lstat $file)[0,1,7,9] ];
   }

This doesn't create @stats, nor have to lookup the second indirection
in  $dirs{$entry}{$_}.

>     elsif (-r _ && -d _ && -x _) {
>       print "\t\t$name -> D $file\n" if DEBUG & REPORT;
>       lookat($file) unless exists($opts{norecurse});
>     } 
>   }
>   closedir(DIR);
>   if ($opts{'moresync'}) {
>     loadix($entry);
>     for (keys %{ $dirs{$entry} }) {
>       gonkulate($entry,$_) if $dirs{$entry}{$_}[0] eq '0';

This would become:
      for (keys %entry) {
        gonkulate($entry,$_) if $entry{$_}[0] eq '0';

>     }
>     rend_thee($entry) if exists($meta{$entry}{nuptdate});
>   }

Then (assuming this data is needed elsewhere):

    $dirs{$entry} = { %entry };

> }

None of these things are really high impact, though.
I *have* seen this sort of thing make many minutes of difference on a
slow system and a big job....depending on your definition of big....

Paul

=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=============================================================
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to