Hi reciter!
The code below shows how I handle checks to be applied on more than one file:
- I use File::Find to loop through all files
- With the sub checkFile I do some basic checking on each of the files (e.g. if it is empty)
- With sub analyze I open a relevant file and process it; if you use the same approach, you'll move most of your code into that function
HTH, Rata
use File::Find;
use File::stat;
find(\&checkFile, $path); # loop through all files in my directory
#--------------------------------- check to be applied on each file --
+-----------
sub checkFile
{
my $fullfilename = $File::Find::name;
my $filesize = stat($File::Find::name)->size;
my $filename = $_;
# --- check for relevance based on expected filenames
if ((! ($filename =~ /_obj_pp_comp.txt/ )) && (! ($filename =~ /ob
+j.doc/ ))) {
return;
}
if ($filesize == 0) {
print ("<!-- \t\tERROR: file $fullfilename is empty. -->\n");
+ return;
}
if (! -f $filename) {
print ("<!-- \t\tERROR: file $fullfilename is a directory. -->\
+n"); return;
}
analyze($fullfilename);
}
#--------------------------------- work to be done on each relevant fi
+le -------------
sub analyze
{
...
}