Next | Program Repair Shop | 153 |
for my $row (0..2) { for my $column (0..2) { if ($squares->[$row][$column] eq "") { print_cell($squares, $page, $column, $row); } else { print ("<td>" . $squares->[$row][$column] . "</td>\n"); } } print ("</tr><tr>\n") unless $row == 2; }
We can avoid the special case here
The structure of the code should echo the structure of the output
In the original code, no part of the program corresponds to a single row
for my $row (0..2) { print "<tr>"; for my $column (0..2) { if ($squares->[$row][$column] eq "") { print_cell($squares, $page, $column, $row); } else { print ("<td>" . $squares->[$row][$column] . "</td>\n"); } } print "</tr>\n"; }
"If the code is well-designed, it can often handle both cases the same way"
Next | Copyright © 2002 M. J. Dominus |