我试图在嵌套的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}
在输出中为空.
错误是什么?
您正在尝试使用一个$mapping
不存在的变量.有一个被调用%mapping
的元素被调用,$mapping{$outlook}
但$mapping
如果它存在则是一个无关的标量,而不是散列的一部分.
看起来你应该使用它 $hashref->{$mapping{$outlook}}