When run, both arrays are the same. With the first active line changed to my @PP = my @OO; with no initialization, the code works as expected; i.e., the @PP array is unchanged. Why the difference??#!/usr/bin/perl # fill two 25 x 25 arrays with zeros, then modify a couple of cells my @PP = my @OO = (1..25); # fill PP and OO arrays with zeros for($rr = 0; $rr < 25; $rr++) { for($cc = 0; $cc < 25; $cc++) { $PP[$rr][$cc] = 0; $OO[$rr][$cc] = 0; } } # uncommenting the below shows array PP zeroed out for my $row (@PP) { print join(",", @{$row}), "\n"; } print "\nAfter:\n"; $OO[1][1]=1; # just so it will be easy to spot $OO[2][2]=2; $OO[3][3]=3; $OO[4][4]=4; # code below. shows the values inserted into array OO cells appearing +in PP cells ??? print "PP array\n"; for my $row (@PP) { print join(",", @{$row}), "\n"; } print "\nOO array\n"; for my $row (@OO) { print join(",", @{$row}), "\n"; } exit;
In reply to Array wierdness by lgp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |