my $crazy_hash = {
'One' => 1,
'Two' => 1,
'Three' => 1,
};
foreach my $num (keys %crazy_hash) {
#DoSomething
}
The error I get is:
Global symbol “%crazy_hash” requires explicit package name at blah line blah
If I do my %crazy_hash and define it within the loop, it works. Why doesn’t it work as is?
$crazy_hashis a reference to an anonymous hash. Prior to 5.14, you need to dereference the reference for keys to work:Starting with 5.14: