下面的代碼提供了錯誤:全局符號「$地」需要在main.pl線19
#!/usr/local/bin/perl
use strict;
use warnings;
my @ground=();
sub map_gen{
my $width=10;
my $height=10;
foreach my $x(0..$width){
foreach my $y(0..$height){
[email protected]{$ground[$x]},"-";
}
}
}
&map_gen;
foreach my $y([email protected]{$ground}){
foreach my $x([email protected]{$ground[$y]}){
print $ground[$x][$y];
}
print"\n";
}
我研究這個錯誤,明確包名這是由於引用了一個未聲明的變量,但是我在錯誤出現之前聲明瞭@ground。我懷疑這是因爲它是一個標量引用,但不知道如何糾正它。
旁註;喜歡'map_gen();'over'&map_gen;'=> http://stackoverflow.com/questions/8912049/difference-between-function-and-function-in-perl –
@mpapec:把超鏈接放入評論使用'文本](http:// ...)' – Borodin