Next | Program Repair Shop | 160 |
The program still has a bug as a result of eliminating the ?'s
print_final_table should generate ?s on output
It no longer does
First let's eliminate repeated code:
414 foreach $x(0..2) { ##print first row
415 print ("<td align=center>" . $squares->[0][$x] . "</td>\n");
416 }
417 print ("</tr><tr valign=middle>\n");
(Repeat twice more.)
Instead, use a for loop:
for my $row (0..2) {
for my $col (0..2) {
print ("<td align=center>" . $squares->[$row][$col] . "</td>\n");
}
print ("</tr><tr valign=middle>\n") unless $row == 2;
}
8 lines become 4
Next | Copyright © 2002 M. J. Dominus |