SiNoEvol has asked for the wisdom of the Perl Monks concerning the following question:
Hello Wise Monks,
I'm a little new to perl and I've run into a little problem working with 2d arrays that seems simple but I've tried it many different ways I run into the same problem over and over again.
#!\usr\perl\bin -w use strict; use warnings; open FILE, "<", "SandSim.txt"; my @sandGrid; while(my $line = <FILE>){ chomp($line); push(@sandGrid, split('', $line)); } close FILE; printSand(@sandGrid); sub printSand{ my @array2d = @_; for my $i (0..$#array2d){ for my $j (0..$#array2d){ print "$array2d[$i][$j]"; } print "\n"; } }
I run into the same runtime error when I run the code.
Can't use string(".") as an ARRAY ref while "strict refs" in use at FallingSand.pl line 21.Here's the file I'm taking the data from if that helps:
..... # # .
I don't seem to have making the file into a 2d array but I just can't print it.
|
|---|