$ 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