develooper Front page | perl.beginners | Postings from February 2002

RE: Help can't figure this one out

Thread Previous | Thread Next
From:
Bob Showalter
Date:
February 14, 2002 05:47
Subject:
RE: Help can't figure this one out
Message ID:
2E4528861499D41199D200A0C9B15BC031B83F@taylorwhite.com
> -----Original Message-----
> From: Bruce Ambraal [mailto:bambraal@cct.org.za]
> Sent: Thursday, February 14, 2002 1:24 AM
> To: beginners@perl.org; beginners-cgi@perl.org
> Subject: Help can't figure this one out
> 
> 
> I have written following coding to produce a triangle 
> pattern(see below);
> I now want to  produce following paterns I can't figer this out
>
> ...
>
>     # indent by printing num_rows - r spaces
>     for ($i = 1; $i <= $num_rows - $r; $i++) {print ("  \n");}

A suggestion: if you want to write Perl programs, you should 
resist the temptation to write them like C programs. This kind 
of thing can be simplified to something like:

   print "  \n" for 1 .. ($num_rows - $r);

or better yet:

   print "  \n" x ($num_rows - $r);

If you haven't done so already, grab a copy of Schwartz'
Learning Perl and work through it. That will show you some
of the idioms that can greatly simplify your programs.

(BTW, are you aware that this statement does not do what the 
comment says it does. You should fix one or the other.)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About