我跑了一个分子动力学模拟,给了我2000个轨迹文件。这些文件的文件名格式为au25-c2-benzalacetone.001
,最高为2000.我编写了一个普通的perl程序,但它没有读取2000个文件。如何修改我的代码以便它读取每个文件并分别提取每个文件的坐标?我需要2,000 coordinates_of_interest.dat
文件。这里的修补程序文件是au25-c2-benzalacetone
文件。这是我写的代码:如何在Perl上正确指定这些变量?
#!/usr/bin/env perl
use Math::VectorReal;
use Math::Trig qw/acos/;
use strict;
use warnings;
my $file1 = $ARGV[0];
my $n1 = $ARGV[1];
my $n2 = $ARGV[2];
my $tinker_file = sprintf "%s.%03d"
my($file1, $n1, $n2) = @ARGV;
foreach $tinker_file (glob "$tinker_file.*") {
print "Filename: $tinker_file\n";
}
my $file2 = "coordinates_of_interest.dat";
my %lines_of_interest = map { $_ => 1 } 18, 25, 26;
{
open(FILE2, '>', $file2) or die "couldn't open the file!";
for(my $i=$n1;$i<=$n2;$i++){
{
open(FILE1, '<', $tinker_file) or die "couldn't open the file!";
{
my $num_lines = keys %lines_of_interest;
while (<FILE1>) {
if ($lines_of_interest{$.}) {
print FILE2;
last unless --$num_lines;
}
}
}
}
}
}
〜
〜
〜
您需要解决几个语法错误(''上$ n1'和'$ n2' my'),'$ i'不与'my',你的'for'未与关闭'}'宣布,你的第一个'open'没有正确终止(缺少')'...)。你应该也可以暗示'close()'你的文件句柄。 –
是的。我即将在此处进行编辑。我运行了代码,它给了我FILE1和FILE2的问题。 –
谢谢@DravSloan –