![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Location: texas
Posts: 3
Rep Power: 0
![]() |
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. thanks |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
In perl, you can't pass arguments via the subroutine definition. Instead, you pull the subroutine's arguments from the list @_. Try this instead:
perl Syntax (Toggle Plain Text)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Learning Perl | ReggaetonKing | Perl | 42 | Oct 20th, 2006 4:42 PM |
| Debug recursion method() | pr0gm3r | Java | 3 | Oct 11th, 2005 12:33 PM |
| Recursion | Mjordan2nd | Coder's Corner Lounge | 22 | Jul 7th, 2005 11:26 AM |
| Why do most shared hosting services offer php not perl? | Jonnno | Perl | 5 | May 19th, 2005 3:56 PM |
| Learning and Programming Perl | G.I.Josh | Perl | 2 | Mar 23rd, 2005 1:48 PM |