Perl 满足条件后,循环不工作
我有两个文件myresult和annotation。这些档案的详情如下。 我的结果:Perl 满足条件后,循环不工作,perl,Perl,我有两个文件myresult和annotation。这些档案的详情如下。 我的结果: 288..639 1.13075739182609-6.20035408429888i 300..651 1.90372125344918-6.09008858828515i 312..663 1.6908117147722-5.67058877579329i 324..675 0.644484787809351-5.54571698740166i 336..687 1.21850904281332-5.477
288..639 1.13075739182609-6.20035408429888i
300..651 1.90372125344918-6.09008858828515i
312..663 1.6908117147722-5.67058877579329i
324..675 0.644484787809351-5.54571698740166i
336..687 1.21850904281332-5.47700589647424i
注释:
272..1042
1649..2629
For循环在满足If条件后仅运行一次。即使在满足条件后,它也不会再次进入循环。例如,在文件myresult中,第2行满足条件,即数字300..651位于文件注释的第1行范围内,因此它打印300到651之间的所有值。但当它需要进入下一轮(第3行),即312..663时,它不会进入该循环,因为该范围也位于文件注释的第1行。
所以输出应该是从300到663的数字,但它只是从300打印到651。
代码:
#/usr/bin/perl
使用数学::复杂;
open($inp0),文件“myresult”的第二列包含复数,例如“1.13075739182609-6.2003540842988i”
两个复数不能比较。(复数是具有实轴和虚轴的复平面的向量。两个向量不能像整数一样进行比较。)
对于文件“myresult”中的所有数据,“($col2>1.60)”将为false。这就是为什么不执行for循环。正如Fumu所说,两个复数无法比较
如果您需要有关Perl中复数的帮助,请查看模块
#!/usr/bin/perl
use Math::Complex;
open( $inp0, "<myresult" ) or die "not found";
open( $inp2, "<annotation" ) or die "not found";
my @arr2 = <$inp0>;
my @arr4 = <$inp2>;
my @result;
foreach my $line1 (@arr2) {
my ( $col1, $col2 ) = split( /\s/, $line1 );
if ( $col2 > 1.60 ) {
my ( $from1, $to1 ) = split( /\.\./, $col1 );
foreach my $line2 (@arr4) {
my ( $from2, $to2 ) = split( /\.\./, $line2 );
for ( my $i = $from1; $i <= $to1; $i++ ) {
for ( my $j = $from2; $j <= $to2; $j++ ) {
$res = grep( /$i/, @result );
if ( $i == $j && $res == 0 ) {
print "$i \n";
push( @result, $i );
}
}
}
}
}
}