Factorial in Perl

Example for versions rakudo-2010.08

This version uses the reduction metaoperator to multiply every number from 1 to N (the leading [*] means “apply the * operator between each element of the following list”).

Note that the say statement could also be written as:

say "$i! = &fact($i)";

with the function call interpolated directly into the string being printed.

sub fact($n) { [*] 1..$n }

for 0..16 -> $i {
    say "$i! = ", fact($i);
}