in reply to Re^2: Printing a hollow square of Asterisks
in thread Printing a hollow square of Asterisks
Even self-imposed homework is homework, but in this case I think you will be a willing participant if I tell you we'll be happy to help you think it through and even tell you once you've got it right, but not to give the answer. :-)
So here is a review of your code:
# *always* use these - they do (some of) your error # checking for you! - saves *lots* of time use strict; use warnings; #this is right my $x = 4; my $y = 4; for (1..$x) { #this bit is wrong - see discussion below print "*" x $y, "\n"; }
The bit I marked wrong is where your problem is. To get a hole in the middle you need dark space for the edges, i.e. asterisks and white space for the hole, i.e. spaces. If you print "*" x $y you will just get the dark stuff and no white space. So how do you get white space? Ask yourself these questions:
Printing out the top and bottom is easy: you have that bit already - just print out a solid line of asterisks. But what about the middle? Here's how to think that through:
When you've thought this through, update your original post with the changes. If it still isn't working quite right, I'm sure people will be glad to help you further.
Best, beth
|
|---|