I am trying to read a directory which consists of hundreds of files. For every file in the directory, I am supposed to access(edit) an another file and replace a particular string 'information=filename' in that file by file names 'information=' present in '/home/test/test_these_files' directory. This is followed by executing the file '/home/test/controlfile.txt'. I have written the following script and have tried to pass names of files as an array to replace (filenames in string). I know that wont work, but I am not sure what will work. Any suggestions? FYI: the program doesn't show any compilation error.
#!use/bin/perl
use strict;
use warnings;
my $find = 'information=filename';
opendir (DIR, "/home/test/test_these_files") || die "can't open directory";
my @files = grep(/.aa/, readdir(DIR));
print @files;
print "\n";
closedir(DIR);
foreach (@files) {
my $replace = 'information=<@files>'; # want to replace with 'information=<filenames>
#filenames are names of files present in the '/home/test/test_these_file' directory
open (FILE, '/home/test/controlfile.txt') || die "cant open file \n";
my @body = <FILE>;
print @body;
open (OUT, '>/home/test/controlfile.txt') || die "can't create file \n";
foreach $_ (@body) {
(s/$find/$replace/g);
print OUT "$_";
}
'perl /home/test/controlfile.txt';
close(FILE);
close(OUT);
}
exit;