Next | Program Repair Shop | 184 |
Close your eyes if you're not interested in tricks:
do_with_board { if ($move eq "$x$y") { $squares->[$x][$y] = "x"; ## define array element for choice } };
We can make this work as follows:
sub do_with_board (&) { local ($x, $y); my $code = shift; for $x (0..2) { for $y (0..2) { $code->(); } } }
With these changes, 18 lines become 7
Final result: 231 lines become 122
That's enough for today
Next | Copyright © 2002 M. J. Dominus |