我有以下需要更正的代码,如defined(@array)
在最新的 Perl 中已弃用。
my @inputs = (
( defined @{$padSrc->{inouts}} ? @{$padSrc->{inouts}} : () ),
( defined @{$padSrc->{inputs}} ? @{$padSrc->{inputs}} : () )
);
我不想搬到if ( @{ $padSrc->{inouts} } )
一种方法,因为这会增加我的行数。
defined(@array)
从来没有做过看起来像做的事情。它总是只返回是否@array
是非空的。
perl5.10.1 -E 'say defined(@foo)' # ""
perl5.10.1 -E '@foo=(); say defined(@foo)' # ""
perl5.10.1 -E '@foo=(42); say defined(@foo)' # "1"
perl5.10.1 -E '@foo=(undef); say defined(@foo)' # "1"
任何你测试的地方defined(@array)
在您的代码中,您可以将其替换为@array != 0
or scalar(@array)
并且您的代码将完全相同(加上或减去一些弃用警告)。
As if (condition) ...
or (condition) ? expr1 : expr2
or while (condition)
总是评价condition
在标量环境中,scalar
在这些结构中是可选的,您可以替换,例如if (defined(@foo))
with if (@foo)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)