在执行以下代码段时。我可以看到一个错误 Global symbol "$colors" requires explicit package name.必须打印键和值

While executing the following snippet. I could see an error Global symbol "$colors" requires explicit package name. Key and value has to be printed

尝试使用 for 循环打印水果及其颜色。

use strict; 
my %colors = (  apple      => 'red',
                orange     => 'orange',
                watermelon => 'green',
                grapes     => 'blue',
                rest       => 'pink' );
for (keys %colors) {    
   print("color of  $_  is   $colors($_)\n"); 
}

$colors($_) 必须是 $colors{$_}

访问哈希值需要使用{ }