0

我在将文件复制到基本上是 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`;
4

1 回答 1

0

我将代码重新编码为纯 Perl(而不是脱壳)。使其更易于阅读。我希望您不要使用前十年的 5.8 之前的 Perl,否则此代码将太“现代”。

我注意到您希望“$Input_FilePath”与“$Source_Path”相同。是这样吗?你也解析 $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;
于 2015-04-08T13:23:26.697 回答