develooper Front page | perl.beginners | Postings from May 2008

Re: Writing side of square

Thread Previous | Thread Next
From:
Chas. Owens
Date:
May 5, 2008 14:18
Subject:
Re: Writing side of square
On Mon, May 5, 2008 at 11:18 AM, Stephen Kratzer <kratzers@pa.net> wrote:
snip
>  for (1..$n) {
>         if ($_ == 1 || $_ == $n) {
>                 print "*" x $n, "\n";
>         }
>         else {
>
>                 print "*", " " x ($n - 2), "*\n";
>         }
>  }
snip

Its time to play TIMTOWTDI:

#!/usr/bin/perl

use strict;
use warnings;

my $n = 10;
my $i = $n - 2;
print "*" x $n, "\n", (map "*"." " x $i."*\n", 1 .. $i), "*" x $n, "\n";
print "*" x $n, "\n", ("*", " " x $i, "*\n") x $i, "*" x $n, "\n";

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About