bengmau has asked for the wisdom of the Perl Monks concerning the following question:

Is there a better way to move results of $rule->in to a file other than placing the results in an array and then streaming the array into a file? It's sucking a lot of memory.
my $rule = File::Find::Rule->new; $rule->file; $rule->name( '*.tmp' ); #find all xml files $rule->mtime("<$timeback"); my @files = $rule->in( $startdir ); ##give me all xml files dating +past $daysback from $startdir ## subroutine me? ## what to do with it my $file = "output.log"; open (OUT,">$file"); foreach (@files) { print OUT $_."\n"; ## move and tar it here } close (OUT);

Replies are listed 'Best First'.
Re: stream results directly to a file
by mattriff (Chaplain) on Feb 04, 2005 at 16:44 UTC
    Instead of in(), use start() and then match() to iterate over it one at a time.

    use File::Find::Rule; my $rule = File::Find::Rule->new; $rule->file; $rule->name( '*.tmp' ); $rule->start($startdir); while (my $file = $rule->match) { print "$file\n"; }
      beauty. thanks!
Re: stream results directly to a file
by Tanktalus (Canon) on Feb 04, 2005 at 16:46 UTC

    Just from looking at the documentation to File::Find::Rule, I'd say something like this:

    my $rule = File::Find::Rule->new; $rule->file; $rule->name( '*.tmp' ); #find all xml files $rule->mtime("<$timeback"); my $file = "output.log"; open(OUT, ">$file"); $rule->start($startdir); while (my $file = $rule->match()) { print OUT $file, "\n"; ## move and tar it here } close(OUT);
    (Completely untested of course - I don't even have F::F::R installed...)