Recursive subroutine : Recursive « Subroutine « Perl






Recursive subroutine

   

sub factorial
{
    my $value = shift (@_);

    return $value == 1 ? $value : $value * factorial ($value - 1);

}

$result = factorial(6);

print $result;

   
    
    
  








Related examples in the same category

1.Recursive factorial subroutine
2.Recursive fibonacci function.
3.Write recursive subroutines
4.calculate 1000th element of standard Fibonacci sequence
5.factorial with recursive function
6.A recursive subroutine to perform arithmetic.