in reply to Re: Searching for files efficiently help!
in thread Searching for files efficiently help!

Do you mean something like this?
#!/usr/bin/perl -w use strict; use File::Find::Rule; my $startdir = "/allfiles"; my @filelist = qw(1234567_bc_20101000.txt 99877_xy_20111111.txt); #for +testing my %filelist = map {$_, 1} @filelist; my $includeFiles = File::Find::Rule->file ->name('*.txt'); # search by file extensi +ons my @files = File::Find::Rule->or( $includeFiles ) ->in($startdir); #locate only txt files in the starting directory my $includeFiles = File::Find::Rule->file ->name('*.txt'); # search by file extensi +ons my @files = File::Find::Rule->or( $includeFiles ) ->in($startdir); my $f_name; my $c=0; foreach my $files(@files) { $c++; if($files=~/(.*?)\/([^\/]+)$/) { $f_name = $2; } if (exists $filelist{$f_name}) { print "$c - Found and to be deleted: $files\n"; } }

But when I print the results I am getting all files and not only the ones that was found!
Thanks!

Replies are listed 'Best First'.
Re^3: Searching for files efficiently help!
by jethro (Monsignor) on Nov 17, 2011 at 13:15 UTC

    Can't confirm your observation. I tested this script and it worked as expected, after throwing away the duplicate lines "my $includeFiles = ..." and "my @files = ..".