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

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

Replies are listed 'Best First'.
Re^3: feed File::Find::Name from a list
by HeadScratcher (Novice) on Oct 05, 2004 at 22:02 UTC
    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>);.
Re^3: feed File::Find::Name from a list
by jdporter (Paladin) on Oct 06, 2004 at 13:56 UTC
    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; }