我想要这种输出:
job cpu-param-14.25.sh job gpu-param-14.25.sh .. .. job cpu-param-15.75.sh job gpu-param-15.75.sh job cpu-param-16.25.sh job gpu-param-16.25.sh .. job cpu-param-18.sh job gpu-param-18.sh
这是我的代码:
#!/usr/bin/perl -w
$incr=0.25;
my $filename = 'job-submit-14.25-18.sh';
open (my $BATCHFILE, '>', "$filename");
$dihed=14.25;
while ($dihed <= 18.0) {
if ($dihed != 16.0) {
$dihed += $incr;
}
print $BATCHFILE
"
job cpu-param-$dihed.sh
job gpu-param-$dihed.sh
"
}
close ($BATCHFILE);
请帮帮我。
答案 0 :(得分:3)
$incr=0.25;
...
$dihed=14.25;
while ($dihed <= 18.0) {
if ($dihed != 16.0) {
$dihed += $incr;
}
...
}
此循环以$dihed
为14.25
开始,并在每一步中以$incr
为0.25递增。这样$dihed
最终将到达16.0
。这种情况在您的代码中已明确处理,因此不会增加$dihed
,这意味着$dihed
从那时起将始终保持16.0
,并且您的代码将永远循环。
鉴于您的输出应该是什么的描述(即它应该忽略16.0
),您的代码更有可能应该始终递增,而跳过16.0
的输出:
$incr=0.25;
...
$dihed=14.25;
while ($dihed <= 18.0) {
$dihed += $incr;
if ($dihed == 16.0) {
next; # skip output for 16.0
}
...
}