in reply to feed File::Find::Name from a list

Does it work better if you chomp the lines you read from the file?

while (<JPG>) { chomp; # save so F::F doesn't overwrite my $extension = qr/$_/; find( sub { push @foundfiles, $File::Find::name if /$extension/; }, + @directories ); }

Replies are listed 'Best First'.
Re^2: feed File::Find::Name from a list
by Thelonius (Priest) on Oct 05, 2004 at 21:06 UTC
    This works, but it would be much faster to do the find only once:
    ... chomp(@jpeg) my $pattern = join("|", @jpeg); find( sub { push @foundfiles, $File::Find::name if /$pattern/o }, @dir +ectories ); open (OUT, ">>I:\\temp\\Outlist.txt") || die "can't open jpgfiles"; print OUT join("\n",@foundfiles), "\n"; close(OUT);
      Thanks for your perls of wisdom but i'm getting the same "Global symbol "$jpglist" requires explicit package" name errors i got befor. I copied / pasted your thoughts to get the following so what am i doing wrong?
      use strict; use File::Find; my @directories = (".", "I:\\temp\\"); my @foun0dfiles; print "Please drag error list \n\t\t"; chop($jpglist=<STDIN>); open (JPG, "$jpglist") || die "can't open JPG"; @jpeg = <JPG>; close(JPG); chomp(@jpeg) my $pattern = join("|", @jpeg); find( sub { push @foundfiles, $File::Find::name if /$pattern/o }, @dir +ectories ); open (OUT, ">>I:\\temp\\Outlist1.txt") || die "can't open jpgfiles"; print OUT join("\n",@foundfiles), "\n"; close(OUT);
        use diagnostics; gives a little more info:
        (F) You've said "use strict vars", which indicates that all variables must either be lexically scoped (using "my"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").
        Also, you should use chomp instead of chop to strip off a trailing newline. So you need something like chomp(my $jpglist=<STDIN>);.
      Yes; but IMHO regex is not the optimal WTDI.
      my %files; @files{@jpeg} = (); find( sub { push @foundfiles, $File::Find::name if exists $files{$_} } +, @directories ); { my $outfile = "I:\\temp\\Outlist.txt"; open OUT, ">> $outfile" or die "can't append to $outfile: $!"; local $, = local $\ = "\n"; print OUT @foundfiles; close OUT; }