View Single Post
Old Nov 5th, 2006, 9:40 PM   #1
baldy1324
Newbie
 
Join Date: Oct 2006
Location: texas
Posts: 3
Rep Power: 0 baldy1324 is on a distinguished road
perl error with recursion

hi i have a program that i tweaked from python (which i know) to perl (changed syntax). here is the program.
#!/usr/bin/perl

sub fib($n)
{
        if ($n<2)
        {
                return 1;
        }
        else
        {
                return fib($n-1) + fib($n-2);
        }
}

$n = 1;
while ($n < 42)
{
        print fib($n);
        print " ";
        $n = $n + 1;
}

when i run the program i get the following.
Not enough arguments for main::fib at fibrecursion.pl line 18, near "$n)"
Execution of fibrecursion.pl aborted due to compilation errors.
any help would be appreciated
thanks
baldy1324 is offline   Reply With Quote