我在将文件复制到基本上是GlusterFS挂载共享的文件夹时遇到问题。
我的Perl脚本读取文件,进行一些解析,并创建一个新文件。之后,我将具有不同名称的新创建的文件复制到其他位置。
我收到此错误
bin/cp: skipping file `/gfs_share/abc/xyz/aktar.txt', as it was replaced while being copied
我的perl代码:
foreach my $Id (@Studies){
my $Trigger_Start_1 = my $Trigger_End_1 = 0;
open(FILE,"$File_path") or die "In gen : Couldn't open file $File_path $! \n";
while(<FILE>){
chomp($_);
if($_ =~ /#INPUT_TYPE\s*(.*)/){
next;
}if($_ =~ /^ID\s+$Id/){
$Trigger_Start_1 = 1;
system ("echo 'Startstudy '>> $Input_FilePath/aktar.txt");
system ("echo '$_' >> $Input_FilePath/aktar.txt");
next;
}if(($Trigger_Start_1 == 2) && ($_ =~ /Endstudy/)){
$Trigger_End_1 = 0;
$Trigger_Start_1 = 0;
system ("echo '$_' >> $Input_FilePath/aktar.txt");
}
if($Trigger_Start_1 == 1){
if($_ =~/Disease\d*_run\d*/){
system ("echo '$_' >> $Input_FilePath/aktar.txt");
next;
}else{
system ("echo '$_' >> $Input_FilePath/aktar.txt");
}
$Trigger_Start_1 = 2;
next;
}
if(($Trigger_Start_1 == 2) && ($Trigger_End_1 == 0)){
system("echo '$_ ' >> $Input_FilePath/aktar.txt");
}
}
}
system ("echo 'Endvalidation '>> $Input_FilePath/aktar.txt");
close(FILE) or die "In gen : Unable to Close File $! \n";
`sed "s/#INPUT_TYPE $Input_Type//" input.txt > input1.txt`;
`sed "s/#DELTA_SET YES 5//" input1.txt > input.txt`;
`cat input.txt >> $Input_FilePath/aktar.txt`;
system ("echo 'INPUT : $Input_FilePath'>> $Input_FilePath/aktar.txt");
system("rm -rf $File_path") if(-e $File_path);
`/bin/cp $Source_Path/aktar.txt $To_Path`;
答案 0 :(得分:0)
我将代码重新编写为纯Perl(而不是shelling)。使阅读更容易。我希望你不要使用前几十年的5.8 Prel或者这个代码太过&#34;现代&#34;。
我注意到你期望&#34; $ Input_FilePath&#34;与&#34; $ Source_Path&#34;相同。是这样的吗?你也解析$ Source_Path和input.txt。似乎没有连接,它们是两个不同的文件吗?
use File::Path;
use File::Copy;
use FileHandle;
my $aktarfile = "$Input_FilePath/aktar.txt";
my ($inh, $aktarh, $inputh);
open $aktarh, '>>', $aktarfile or die "Unable to open [$aktarfile] for writing\n";
$aktarh->autoflush();
foreach my $id (@Studies){
my $Trigger_Start_1 = my $Trigger_End_1 = 0;
open $inh, '<', $File_path or die "In gen : Couldn't open file $File_path $! \n";
LINE:
while(<$inh>){
chomp($_);
if($_ =~ /#INPUT_TYPE\s*(.*)/){
next LINE;
}if($_ =~ /^ID\s+$id/){
$Trigger_Start_1 = 1;
print {$aktarh} "Startstudy\n$_";
next LINE;
}if(($Trigger_Start_1 == 2) && ($_ =~ /Endstudy/)){
$Trigger_End_1 = 0;
$Trigger_Start_1 = 0;
print {$aktarh} $_;
}
if($Trigger_Start_1 == 1){
print {$aktarh} $_;
if($_ !~/Disease\d*_run\d*/){
$Trigger_Start_1 = 2;
}
next LINE;
}
if(($Trigger_Start_1 == 2) && ($Trigger_End_1 == 0)){
print {$aktarh} $_;
}
}
close $inh or die "In gen : Unable to Close File $! \n";
}
print {$aktarh} "Endvalidation\n";
my $inputfile = 'input.txt';
open $inputh, '<', $inputfile or die "Failed to open [$inputfile] for reading";
while(<$inputh>){
s/#INPUT_TYPE $Input_Type//;
s/#DELTA_SET YES 5//;
print {$aktarh} $_;
}
print {$aktarh} "INPUT : $Input_FilePath\n";
close $aktarh or die "Failed closing [$aktarfile]";
File::Path::remove_tree($File_path) if(-e $File_path);
File::Copy::copy "$Source_Path/aktar.txt", $To_Path;