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

Re: Writing side of square

Thread Previous | Thread Next
From:
Stephen Kratzer
Date:
May 5, 2008 08:18
Subject:
Re: Writing side of square
On Monday 05 May 2008 09:22:51 Rodrigo Tavares wrote:
> Hello,
>
> I need create a square using a single number, but I don't know how to
> create the sides.
>
> I have to create this:
>
> ****
> *  *
> *  *
> ****
>
> My code is below :
>
> print "Enter with number:";
> chomp ($number = <STDIN>);
>
> my @array = ();
>
> $cont = 0;
>
> while ($numero > $cont)
>  {
>  	$array[$cont]="*";
>  	$cont++;
>  }
>
>  print @array;
>  print "\n";
>  print @array;
>  print "\n";
>
> How I can to show the arrar like sides ?
>
> []'s
>
> Faria
>
>
>       Abra sua conta no Yahoo! Mail, o único sem limite de espaço para
> armazenamento! http://br.mail.yahoo.com/

for (1..$n) {
        if ($_ == 1 || $_ == $n) {
                print "*" x $n, "\n";
        }
        else {
                print "*", " " x ($n - 2), "*\n";
        }
}

Thread Previous | Thread Next


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