T
Toralf Förster
In the following program I'd expect that line 29 fills @Values with zeros, but for i==2 this is counterproofed.
Why ?
$ nl -ba zero.pl
1 #!/usr/bin/perl
2
3 # Toralf Förster
4 # Hamburg
5 # Germany
6
7 use strict;
8 use diagnostics;
9 $diagnostics:RETTY = 1;
10
11 use warnings FATAL => 'uninitialized';
12 use Carp ();
13 $SIG{__DIE__} = \&Carp::confess;
14
15
16 my $Cols = 30;
17 my $Rows = 16;
18
19 my @Zero = ();
20 foreach my $r (0..$Rows+1) {
21 foreach my $c (0..$Cols+1) {
22 $Zero[$r][$c] = 0;
23 }
24 }
25
26 my $N = 10;
27 foreach my $i (1..$N) {
28
29 my @Values = @Zero;
30
31 foreach my $r (0..$Rows+1) {
32 foreach my $c (0..$Cols+1) {
33 if ($Values[$r][$c] != 0) {
34 die "i=$i\tr=$r\tc=$c\t$Values[$r][$c]\n";
35 }
36 }
37 }
38
39 foreach my $r (0..$Rows+1) {
40 foreach my $c (0..$Cols+1) {
41 $Values[$r][$c] = 1;
42 }
43 }
44 }
45
46
47 exit (0);
48
tfoerste@n22 ~/workspace/misc $ ./zero.pl
i=2 r=0 c=0 1
at ./zero.pl line 34
Why ?
$ nl -ba zero.pl
1 #!/usr/bin/perl
2
3 # Toralf Förster
4 # Hamburg
5 # Germany
6
7 use strict;
8 use diagnostics;
9 $diagnostics:RETTY = 1;
10
11 use warnings FATAL => 'uninitialized';
12 use Carp ();
13 $SIG{__DIE__} = \&Carp::confess;
14
15
16 my $Cols = 30;
17 my $Rows = 16;
18
19 my @Zero = ();
20 foreach my $r (0..$Rows+1) {
21 foreach my $c (0..$Cols+1) {
22 $Zero[$r][$c] = 0;
23 }
24 }
25
26 my $N = 10;
27 foreach my $i (1..$N) {
28
29 my @Values = @Zero;
30
31 foreach my $r (0..$Rows+1) {
32 foreach my $c (0..$Cols+1) {
33 if ($Values[$r][$c] != 0) {
34 die "i=$i\tr=$r\tc=$c\t$Values[$r][$c]\n";
35 }
36 }
37 }
38
39 foreach my $r (0..$Rows+1) {
40 foreach my $c (0..$Cols+1) {
41 $Values[$r][$c] = 1;
42 }
43 }
44 }
45
46
47 exit (0);
48
tfoerste@n22 ~/workspace/misc $ ./zero.pl
i=2 r=0 c=0 1
at ./zero.pl line 34