That would be a great suggestion, except we that we seem to be constrained to integer coordinates.
I can't think of any way to avoid dealing with the four sides of the square separately. You might try replacing the range loop body with something like the fragment below. I think it's somewhat easier to understand, and it doesn't print each corner of the square twice (though it does miss the origin).
my ($x, $y) = ($range, $range);
while ($x > -$range) { print "$x,$y\n"; $x-- }
while ($y > -$range) { print "$x,$y\n"; $y-- }
while ($x < $range) { print "$x,$y\n"; $x++ }
while ($y < $range) { print "$x,$y\n"; $y++ }
This shows why it's nice that perl lets you do what you want with whitespace, unlike some other languages. |