Every now and again I like to program for fun. In this case it is a
simulation. The basis is a grid that holds things like altitude,
pieces and things like that. To hold all data in a way I can remember
everything easily, I chose to put all in a multi dimensional array.
If there is a better way, please do tell. Loading the grid from file
gave me a surprise. The values in the array do not seem to be static.
The change seems to occur after leaving the Reading loop. In this
loop values do not change, calling them after the loop some values
will have changed in a regular manner. References give similar
results
Executing the program below gives a lot of differences. There is a
discernable patern in where those differences occur which leads me to
believe that perl is not at fault here, but me. (As I have sufficient
trust in my programming abillities, that would have been the logical
conclusion anyway.) Especially as another perl version on a linux
machine exhibits the same behaviour. The Perl verion used here is
v5.8.1 built for MSWin32-x86-multi-thread
Question: what am I doing wrong here?
my @GridMulti; # Multi dimensional array: playing field
my $GM_Height = 0; # Height of terrain in units above 0
my $MaxX = 80; # Number of field columns
my $MaxY = 70; # Number of field rows
my $MaxFields = (($MaxX + 1) * ($MaxY + 1)) - 1;
# Number of fields
my @CheckArray1; # First Check Array
my @CheckArray2; # Second Check Array
my $Differences = 0; # Number of differences
#Reading loop. Using rand here to prevent a extremely long post
for my $xiter (0 .. $MaxX) {
for my $yiter (0 .. $MaxY) {
$GridMulti[$xiter . $yiter . $GM_Height] = int (rand 256);
push @CheckArray1, $GridMulti[$xiter . $yiter . $GM_Height];
}
}
#CheckLoop
for my $xiter (0 .. $MaxX) {
for my $yiter (0 .. $MaxY) {
push @CheckArray2, $GridMulti[$xiter . $yiter . $GM_Height];
}
}
for my $iter (0 .. $MaxFields) {
if ($CheckArray1[$iter] != $CheckArray2[$iter]) {
$Differences++;
}
}
print "\n$Differences differences\n";
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>