i don't suppose your taking this class from ltc? if not i've got a similar deadbeat teacher. that problem sounds real similar to one i had in ch 2 of e.b.chang book. if this is the case, you won't need to be using subroutines yet. that's in later chapter.
here's my answer to a:
#!/usr/bin/perl
# Exercise 2.10a
print "This program will create a rectangle given width,\n",
"height and character to use.\n";
# Get width and height from user, verify they will work.
do { #get the width
print "Enter a width between 1 and 80.\n";
chomp($w=<STDIN>);
}
until (0 < $w) and ($w <= 80);
do { #get the height
print "Enter a height between 1 and 24.\n";
chomp($h=<STDIN>);
}
until (0 < $h) and ($h <= 24);
print "Enter a character to use.";
chomp($char=<STDIN>);
# Create the rectangle.
$y=1;
do { #create rows
$x=1;
do { #create columns
print $char;
++$x;
}
until $x == ($w + 1);
print "\n";
++$y;
}
until $y == ($h + 1);
here's b:
#!/usr/bin/perl
# Exercise 2.10b
print "This program will create a rectangle given width,\n",
"height and character to use.\n";
# Get width and height from user, verify they will work.
do { #get the width
print "Enter a width between 1 and 80.\n";
chomp($w=<STDIN>);
}
until (0 < $w) and ($w <= 80);
do { #get the height
print "Enter a height between 1 and 24.\n";
chomp($h=<STDIN>);
}
until (0 < $h) and ($h <= 24);
print "Enter a character to use.";
chomp($char=<STDIN>);
# Create the rectangle outline.
#create top row
$x=1;
do { #create columns
print $char;
++$x;
}
until $x == ($w + 1);
print "\n";
#create middle rows
if ($h > 2) {
$y=1;
$b=" ";
do {
print $char;
++$y;
if ($w > 2) {
$x=1;
do {
print $b;
++$x;
}
until $x == ($w - 1);
print $char
}
print "\n";
}
until $y == ($h - 1);
}
#create bottom row
$x=1;
if ($h > 1) {
do { #create columns
print $char;
++$x;
}
until $x == ($w + 1);
print "\n";
}
get's kind of lengthy without subs