有人可以解释这里的实际错误以及如何解决它?

chr*_*ris 2 perl hash loops

我试图在嵌套的for/foreach循环中使用哈希.见源

strict它说

Global symbol "$mapping" requires explicit package name at ./test2.pl line 39. 
Execution of ./test2.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

没有strict,

Use of uninitialized value $mapping in hash element at ./test2.pl line 46, <$fh> line 8. 
Use of uninitialized value in concatenation (.) or string at ./test2.pl line 46, <$fh> line 8.
Run Code Online (Sandbox Code Playgroud)

print $hashref->{$mapping} 在输出中为空.

错误是什么?

Ala*_*rry 8

您正在尝试使用一个$mapping不存在的变量.有一个被调用%mapping的元素被调用,$mapping{$outlook}$mapping如果它存在则是一个无关的标量,而不是散列的一部分.

看起来你应该使用它 $hashref->{$mapping{$outlook}}