$ perl -Mwarnings -e'my %h = {}'
Reference found where even-sized list expected at -e line 1.
strict和warnings包括用Perl有很好的理由。没有理由不使用它们。
更妙的是,添加diagnostics混进去过:
$ perl -Mwarnings -Mdiagnostics -e'my %h = {}'
Reference found where even-sized list expected at -e line 1 (#1)
(W misc) You gave a single reference where Perl was expecting a list
with an even number of elements (for assignment to a hash). This usually
means that you used the anon hash constructor when you meant to use
parens. In any case, a hash requires key/value pairs.
%hash = { one => 1, two => 2, }; # WRONG
%hash = [ qw/ an anon array/]; # WRONG
%hash = (one => 1, two => 2,); # right
%hash = qw(one 1 two 2); # also fine
你应该认真考虑启用'warnings'编译。它会抓住这个错误。 – rafl 2011-04-12 10:02:22
将这些行放在** ALL **脚本的顶部: use strict; 使用警告; – shawnhcorey 2011-04-12 12:33:48