Fibonacci numbers in Perl
Example for versions
perl 5.8.8
This example uses recursive definition of Fibonacci numbers.
sub fibonacci {
my $n = shift;
$n < 3 ? 1 : fibonacci($n-1) + fibonacci($n-2)
}
foreach (1..16) {
print fibonacci($_), ", ";
}
print "..."
Comments
]]>blog comments powered by Disqus
]]>