Pyramid in perl

Lets say you want to print something like this:

Here is the code I wrote:

# !/usr/bin/perl
@array = (‘A’ .. ‘Z’);
$in = <>;
if($in < 0)
print “Can’t proceed”;
for($i = 0 ; $i < $in ; $i++)
@tmp = (”);
for($k = scalar(@array); $k > $i; $k–)
print ” “;
for($j = 0 ; $j < $i; $j++)
print “@array[$j]”;
@revtmp = reverse(@tmp);
{ print “$_” ;}
print “\n”;

This is a rough attempt at the problem. It can be:
1. Checked for input validity

2. Enhanced with what ever you want to ice on top of it.

Have fun!


3 Responses to “Pyramid in perl”

  1. Bucciarati Says:

    Your piramid is falling! Hold it! Someone think of the children!

  2. vinaychilakamarri Says:

    Yeah I tried to format it for wordpress but apparently the nbsp didn’t jell well with the format of pyramid. But the console showed it kind of OK. Did you mean falling in other sense?

  3. […] defeats the purpose of homework. Google also returns a myrid of results for these questions (like this one), so I'm assuming you haven't googled for this […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: