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

I have a list, in a file, of files which i need to find the full path of How can i do this usin File::Find::Name I can find all the files with an givern extention and i can find 1 file but can't figure out how to feed File::Find::Name from a list This is as far as my thinking ets.
#!/usr/bin/perl -w use strict; use File::Find; my @directories = (".", "I:\\Temp\\"); my @foundfiles; print "Please drag error list \n\t\t"; chop($jpglist=<STDIN>); open (JPG, "$jpglist") || die "can't open JPG"; @jpeg = <JPG>; close(JPG); foreach $line(@jpeg); { find( sub { push @foundfiles, $File::Find::name if /$line/ }, @directo +ries ); open (OUT, ">>I:\\temp\\Outlist.txt") || die "can't open jpgfiles"; print OUT join("\n",@foundfiles), "\n"; close(OUT); }
Thanks Oh Holly ones!!

Replies are listed 'Best First'.
Re: feed File::Find::Name from a list
by chromatic (Archbishop) on Oct 05, 2004 at 19:09 UTC

    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 ); }
      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);
        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; }