next up previous contents
Next: The MatLab implementation Up: The Fibonacci calculator Previous: The C implementation   Contents

The Perl implementation

This code was run on the 5.005 version of the Perl interpreter, compiled for an Intel i386 Linux platform.

#!/usr/bin/perl -w

sub fib {
    my ($n) = @_;
    return $n if ($n <= 2);
    return fib($n-1) + fib($n-2);
}

my $arg = $ARGV[0];

print "fib($arg) = ".fib($arg)."\n";




1999-08-09