【问题标题】:Can someone explain what the actual error is here and how to fix it?有人可以解释这里的实际错误是什么以及如何解决它吗?
【发布时间】:2012-07-27 04:19:49
【问题描述】:

我正在尝试在嵌套的 for/foreach 循环中使用哈希。 see Source

strict 表示

Global symbol "$mapping" requires explicit package name at ./test2.pl line 39. 
Execution of ./test2.pl aborted due to compilation errors.

没有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.

print $hashref-&gt;{$mapping} 在输出中为空。

什么是错误?

【问题讨论】:

  • Use of uninitialized value $mapping 不够清楚?
  • 我认为一些有经验的版主可以编辑这个问题的标题以更好地适应问题。
  • @Victor 你可以随时编辑问题/标题,有人会过来为你批准/不批准。
  • 不错。我不知道(实际上“留给海狸”是我所相信的)。

标签: perl hash loops


【解决方案1】:

您正在尝试使用不存在的名为 $mapping 的变量。有一个名为 %mapping 的元素有一个名为 $mapping{$outlook} 的元素,但如果 $mapping 存在,它将是一个不相关的标量,而不是散列的一部分。

看来你应该使用$hashref-&gt;{$mapping{$outlook}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2020-06-17
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多