You're adding a directory to @filelist
at line 7, then you print all the files in that directory and its subdirectories at line 13.
Line 6 should be:
if ( -f $File::Find::name && $File::Find::name !~ /\.(?:bak|conf|cfg)\z/i ) {
Line 13 should be:
searcher($_) for @filelist;
searcher
should be:
sub searcher {
my ($file) = @_;
print "Searching $file\n";
}
Avoiding global vars, the whole looks like:
sub loadFiles {
my $dir=shift;
my @filelist;
my $wanted = sub {
return if $File::Find::name =~ /\.(?:bak|conf|cfg)\z/i;
return if !-f $File::Find::name;
push @filelist, $File::Find::name;
};
find($wanted, $dir);
return @filelist;
}
sub searcher {
my $file=shift;
print "Searching $file\n";
}
searcher($_) for loadFiles($dir_loc);
(Technically, you could do searcher($File::Find::name);
directly instead of push
ing it to an array then later looping over the array.)