simple perl program to generate pattern of *

August 15, 2011 at 10:36:04
Specs: Windows 7
simple perl program to generate
*
* *
* * *
* * * *
using recursive function...

See More: simple perl program to generate pattern of *

Report •


#1
August 15, 2011 at 15:15:18
no error checking ....

#!/usr/bin/perl

use strict;
use warnings;

astric(4, 1);

sub astric {
my $arg1 = shift;
my $arg2 = shift;
my $i;


for($i=1; $i<=$arg2; $i++)
   {
   printf("%s ", "*");
   }
print "\n";

if ($arg2 == $arg1)
   {
   exit;
   }

astric($arg1, $arg2 + 1);
}


Report •

#2
August 16, 2011 at 07:44:12
#!/usr/bin/perl

use strict;
use warnings;

astric(1, 4);

sub astric {
    my ($cnt, $end) = @_;
    print '* ' x $cnt, "\n";
    astric(++$cnt, $end) unless $cnt == $end;
}


Report •

Related Solutions


Ask Question