The following code gives the error: Global symbol "$ground" requires explicit package name at main.pl line 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){
push@{$ground[$x]},"-";
}
}
}
&map_gen;
foreach my $y(0..scalar@{$ground}){
foreach my $x(0..scalar@{$ground[$y]}){
print $ground[$x][$y];
}
print"\n";
}
I have researched this error and it is due to referencing an undeclared variable, but I declared @ground before the error appears. I suspect it's because its a scalar reference, but dont know how to correct it.