我编写了这个 perl 程序来复制某些类型的文件。当我运行这个程序时,我看到非常烦人且奇怪的错误。
#!/usr/bin/perl -w
use strict;
for (my $LAMBDA=0; $LAMBDA<1.05;$LAMBDA += 0.05) {
print "Processing configuration $LAMBDA...\n";
chdir "Lambda_${LAMBDA}/Production_MD";
system("cp *.tpr ../../dimer_tprs ");
chdir "../..";
}
我看到这个错误。
Processing configuration 0...
Processing configuration 0.05...
Processing configuration 0.1...
Processing configuration 0.15...
Processing configuration 0.2...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.25...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.3...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.35...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.4...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.45...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.5...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.55...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.6...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.65...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.7...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.75...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.8...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.85...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.9...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 0.95...
cp: cannot stat `*.tpr': No such file or directory
Processing configuration 1...
cp: cannot stat `*.tpr': No such file or directory
所以它首先复制 2-3 个,然后它说没有这样的文件或目录,但文件和目录都在那里。请帮忙。
答案1
我看到有两个问题。第一个是浮点数学。浮点数学总是有一些错误,尽管在这种情况下它看起来并不重要。另一个是你没有对你的chdir
s 进行错误检查。我认为 Lambda_0.2/Production_MD 丢失了,这会让你看到的一切都混乱。这可能是一个更简单的解决方案:
find . -maxdepth 3 -mindepth 3 -path "Lambda_*/Production_MD/*.tpr" -print0 |\
grep --null-data -e "Lambda_0\.[0-9]5\?/Production_MD/*.tpr" -e "Lambda_1\.0/Production_MD/*.tpr"|\
xargs -0r cp -t dimer_tprs