Factorial in Perl

Example for versions perl 5.8.8

This example uses iterative factorial definition.

sub fact {
  my $n = shift;
  my $result = 1;
  foreach my $i (1 .. $n) {
    $result *= $i;
  }
  $result
}

foreach my $i (0..16) {
    print "$i! = ", fact($i), "\n";
}