我现在正忙着学习Perl,并且我已经获得了一些代码来查看和“解决”.
foreach $field (keys %$exam)
上面的代码是我难以理解的区域.我认为$是标量而%是哈希值,因此我不确定%$是什么.
任何帮助赞赏!
多谢你们.
解决方法
$exam = {a=>1,b=>2}; # anonym hash,$exam is ref for this hash
为了使用这个ref like hash,你必须在ref之前使用dereferencing operator%
foreach $field(键%$考试)
例如,数组引用相同.
$a = [1,2,3,4]; # anonym arr,$a is ref for this array
因此,您必须在ref $a之前使用operator @进行解除引用
foreach $element(@ $a){print $element;}