gpt4 book ai didi

Perl 警告 : "Found = in conditional, should be ==", 但行上没有等号

转载 作者:行者123 更新时间:2023-12-03 15:07:18 24 4
gpt4 key购买 nike

我在 Mac OS X v10.7.2 上的 Perl v5.12.3 中运行以下内容(狮子):

#!/usr/local/bin/perl

use 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 seven slots, weekdays
# have only four (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, '$times[$t]', $d);");
$counter++;
}
}
}

$db->disconnect;
我收到“Found = in conditional, should be == 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 警告 : "Found = in conditional, should be ==", 但行上没有等号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7960757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com