J
John W. Krahn
I ran across this problem on the Perl beginners mailing list and am
posting here because I am not running the current version of Perl and
would like someone else to confirm this.
The following code should demonstrate the problem:
#!/usr/bin/perl
use warnings;
use strict;
use constant X => 99;
use constant Y => 99;
my @array;
my @check1;
my @check2;
my $diff = 0;
for my $x ( 0 .. X ) {
for my $y ( 0 .. Y ) {
my $i = 0 + ( $x . $y );
$array[ $i ] = int( rand ~0 );
push @check1, $array[ $i ];
}
}
for my $x ( 0 .. X ) {
for my $y ( 0 .. Y ) {
my $i = 0 + ( $x . $y );
push @check2, $array[ $i ];
if ( $check1[ $#check2 ] != $check2[ $#check2 ] ) {
print "$x . $y $check1[$#check2] $check2[$#check2]\n";
$diff++;
}
}
}
print "\n$diff differences from ", X, Y, " entries\n";
__END__
This _should_ print out "0 differences from 9999 entries" but on my
computer I get 900 differences. If I change "my $i = 0 + ( $x . $y );"
to "my $i = $x * 100 + $y;" it works correctly with 0 differences. This
looks like a bug in array indexing.
The original thread is at
http://groups.google.com/groups?threadm=4087A478.18574.7F3DCA@localhost
TIA
John
posting here because I am not running the current version of Perl and
would like someone else to confirm this.
The following code should demonstrate the problem:
#!/usr/bin/perl
use warnings;
use strict;
use constant X => 99;
use constant Y => 99;
my @array;
my @check1;
my @check2;
my $diff = 0;
for my $x ( 0 .. X ) {
for my $y ( 0 .. Y ) {
my $i = 0 + ( $x . $y );
$array[ $i ] = int( rand ~0 );
push @check1, $array[ $i ];
}
}
for my $x ( 0 .. X ) {
for my $y ( 0 .. Y ) {
my $i = 0 + ( $x . $y );
push @check2, $array[ $i ];
if ( $check1[ $#check2 ] != $check2[ $#check2 ] ) {
print "$x . $y $check1[$#check2] $check2[$#check2]\n";
$diff++;
}
}
}
print "\n$diff differences from ", X, Y, " entries\n";
__END__
This _should_ print out "0 differences from 9999 entries" but on my
computer I get 900 differences. If I change "my $i = 0 + ( $x . $y );"
to "my $i = $x * 100 + $y;" it works correctly with 0 differences. This
looks like a bug in array indexing.
The original thread is at
http://groups.google.com/groups?threadm=4087A478.18574.7F3DCA@localhost
TIA
John