On Mon, 30 Apr 2001, Meije Oppenhuizen wrote:

> I am probably doing something very wrong here, but can someone tell me
> why
> 
> #!/usr/bin/perl -w
> 
> use File::Find;
> 
> print "$arg";
> open(LISTFILE, "> /home/meyeo/testfile") or die "Can't open the ffin
> thingy!";
> print LISTFILE "\n";
> close(LISTFILE);
> 
> find (\&wanted, $arg);
> 
> sub wanted
> {
> #  this should print all the files in the serving directory (including
> subdirs)!
> open(LISTFILE, ">> /home/meyeo/testfile") or die "Can't open the ffin
> thingy!";
> print LISTFILE "$_\n";
> close(LISTFILE);
> }

I can't see why it works differently in different places, but
something like this would be MUCH more efficient:

#!/usr/bin/perl -w
use strict;
use File::Find;

my $arg = shift @ARGV;

my @files;

find (sub { push @files, $_ }, $arg);

open LISTFILE, ">>outputfile" or die "Could not open
outputfile: $!";
print LISTFILE join "\n", @files;
close LISTFILE;

.... of course, that will have to keep a list in memory of all the
files it has read so far. If that's a problem, then you can change
it so it will call a "flush_list" function every 5000 file or
something and clear the @files array.


  - ask 

-- 
ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
more than 100M impressions per day, http://valueclick.com


Reply via email to