我遇到了Perl問題。這給了我一個我不明白的錯誤。如何使用Perl全局散列
這是我的計劃
our $neighbor = {};
$$neighbor{'a'} = 'b';
print Dumper($vizinho);
sub keyboard{
my ($a,$b) = @_;
return 4 if ($a eq $b);
return 2 if $neighbor{$a}{$b};
return -1;
}
而且我的錯誤是
Variable "%vizinho" is not imported at t/DistStr.t line 30.
Global symbol "%vizinho" requires explicit package name at t/DistStr.t line 30.
Execution of t/DistStr.t aborted due to compilation errors.
# Looks like your test exited with 255 just after 1.
我想要做的就是
use Alinhamento;
$neighbor = ... # Something which will create an hash where
# $neighbor{$x}{$y} exists if the letter $x is neighbour of $y
sub keyboard {
my ($a, $b) = @_;
return 4 if ($a eq $b);
return 2 if $neighbor{$a}{$b}; #And use that $neighbor on that function
return -1;
}
但我不知道如何使。請給我一些建議嗎?
* vizinho *是葡萄牙語*鄰居* – Borodin
啊,所以它從來沒有被認爲是一個哈希引用!好電話 – Borodin