Perl警告:“发现=有条件的,应该是==”,但是线上没有等号

Perl警告:“发现=有条件的,应该是==”,但是线上没有等号,第1张

概述在MacOS 10.7.2上的Perl v5.12.3中运行以下命令: #!/usr/local/bin/perluse strict;use warnings;use DBI;my $db = DBI->connect("dbi:SQLite:testdrive.db") or die "Cannot connect: $DBI::errstr";my @times = ("13 在MacOS 10.7.2上的Perl v5.12.3中运行以下命令:

#!/usr/local/bin/perluse strict;use warnings;use DBI;my $db = DBI->connect("dbi:sqlite:testdrive.db") or dIE "Cannot connect: $DBI::errstr";my @times = ("13:00","14:30","16:00","17:30","19:00","20:30","22:00");my $counter = 1;for (my $d = 1; $d < 12; $d++) {    for (my $t = 0; $t < 7; $t++) {        #weekend days have 7 slots,weekdays have only 4 (barring second frIDay)        if (($d+4) % 7 < 2 || ($t > 3)) {            $db->do("INSERT INTO tbl_timeslot VALUES ($counter,'$times[$t]',$d);");            $counter++;        #add 4:00 slot for second FrIDay        } elsif (($d = 9) && ($t = 3)) {            $db->do("INSERT INTO tbl_timeslot VALUES ($counter,$d);");            $counter++;        }    }}$db->disconnect;

我得到一个“Found = in conditional,should is == at addtimes.pl line 16”警告,但是那条线上没有等号.此外,循环似乎从$d == 9开始.我错过了什么?

第16行:

if (($d+4) % 7 < 2 || ($t > 3)) {

谢谢.

解决方法 问题在于你的elsif

} elsif (($d = 9) && ($t = 3)) {             ^-----------^--------- should be ==

因为if语句在第16行开始,并且elsif是该语句的一部分,所以这是报告错误的地方.这是Perl编译器的一个不幸的限制.

在一个不相关的说明中,当你可以避免C风格循环时更好:

for my $d ( 1 .. 11 ) {     ...    for my $t ( 0 .. 6 ) {         ...    }}

那不漂亮吗? 总结

以上是内存溢出为你收集整理的Perl警告:“发现=有条件的,应该是==”,但是线上没有等号全部内容,希望文章能够帮你解决Perl警告:“发现=有条件的,应该是==”,但是线上没有等号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1268580.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存