Factorial in Perl
Example for versions
perl 5.8.8
This example uses recursive factorial definition.
sub fact {
my $n = shift;
$n == 0 ? 1 : $n*fact($n-1);
}
foreach my $i (0..16) {
print "$i! = ", fact($i), "\n";
}
Comments
]]>blog comments powered by Disqus
]]>