【发布时间】:2011-08-03 03:36:25
【问题描述】:
如果use strict; 被注释掉,我有几行代码可以工作。但是,我不想仅仅因为一小部分就禁用整个脚本。
我需要重新编码,或者以某种方式暂时禁用use strict;,然后重新启用它。第一个选项比较现实,但我不知道如何将代码更改为在严格模式下工作。
my ($ctc_rec_ref) = get_expected_contacts($ctc,$fy);
my @expected_ctc_rec = @$ctc_rec_ref;
print $expected_ctc_rec[0][0]."\n";
print $expected_ctc_rec[0][1]."\n";
print $expected_ctc_rec[0][2]."\n";
sub get_expected_contacts
{
my (@ctc_rec,$i) = ((),0);
$STMT = "SELECT DISTINCT field1, field2, field3 FROM table WHERE field4 = ? AND field5 = ? AND field6 = 'E'";
$sth = $db1->prepare($STMT); $sth->execute(@_);
while(@results = $sth->fetchrow_array())
{
push @{ $ctc_rec[$i] }, $results[0];
push @{ $ctc_rec[$i] }, $results[1];
push @{ $ctc_rec[$i] }, $results[2];
$i++;
}
return (\@ctc_rec);
}
启用
use strict;:不能使用字符串 ("0") 作为 ARRAY ref 而“严格参考”在使用 ./return5.pl 第 49 行。
(第 49 行:push @{ $ctc_rec[$i] }, $results[0];)
禁用use strict;:
1468778
04/01/2011
30557
如何重写此代码,使其像禁用严格模式一样工作?如果这不可行,是否可以暂时禁用 use strict;,然后为脚本中的这段短代码重新启用?
【问题讨论】:
标签: arrays perl multidimensional-array strict