Dear all
I would like to read every file in a directory, if each file contains a line 'KAC 50' I will write to an output file. My code below write all the out output into only 1 file. How can I have many output files corresponding to the input files?
#!/usr/bin/perl
use strict;
use warnings;
my $outfile = "KAC.pdb";
open(my $fh, '>>', $outfile);
opendir (DIR, "/data/tmp") or die "$!";
my @files = readdir (DIR);
closedir DIR;
foreach my $file(@files){
open (FH, "/data/tmp/$file") or die "$!";
while (<FH>){
my($line) = $_;
chomp($line);
if ($line =~m/KAC 50/){
print $fh $_;
}
}
}
close FH;
Best regards
becon