It's because $key1
is not defined.
You meant to use %{ $file1::hash{$key} }
instead.
Note that if you avoid pre-declaring $key1
, the strict
pragma can catch it at compile-time:
for my $key (keys %file1::hash){
print "$key\n";
for my $key1 (keys %{$file1::hash{$key1}}){
print "$key1\n";
}
}
Message
Global symbol "$key1" requires explicit package name