我正在从这里学习 Perl 脚本。我在创建哈希时遇到问题。代码在这里:
print "Hello World!\n";
@days = ("1", "2");
print "There are $#days days\n";
print "1 is $days[0]\n";
%months = ("a" => 1, "b" => 2, "c" => 3);
print "There are $#months keys\n";
print "a is $months[0]\n";
for $i (keys %months)
{ print "$i has value $months[$i].\n"}
现在它与数组一起工作正常。但是对于 Hash 它的打印“有 -1 个键”。此外,它不会为最后打印调用的变量值打印任何内容。