私は何百ものファイルからなるディレクトリを読もうとしています。ディレクトリ内のすべてのファイルについて、私は別のファイルにアクセス(編集)し、そのファイル内の特定の文字列 'information = filename'を '/ home/test/test_these_files'ディレクトリにあるファイル名 'information ='で置き換えます。これに続いてファイル '/home/test/controlfile.txt'を実行します。私は次のスクリプトを書いて、ファイルの名前を置き換える配列(文字列のファイル名)として渡そうとしました。私はそれが働かないことを知っているが、私は何がうまくいくのか分からない。助言がありますか? FYI:プログラムはコンパイルエラーを表示しません。置き換える必要がある文字列に異なるファイル名を入力する方法は?
#!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;
インデントはあなたの友人です。 '' perl /home/test/controlfile.txt 'とは何ですか? $ replaceは間違って設定されています。 – Schwern