in reply to factorial through recursion
In addition to the previously mentioned missing curlies,
my($num1,$flag)=shift; takes one value from @_ and assigns to the first of two. $flag never gets a value. You want
my $num1 = shift; my $flag = shift;
or
my ($num1, $flag) = @_;
Then there's the issue that your program always dies. Return the value you find instead of dying. This will also allow you to remove the print from fact, which is appropriate since finding the factorial of a number has nothing to do with I/O.
Finally, it's very weird that your factorial function takes two inputs. That's inconsistent with the mathematical function.
Solution:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: factorial through recursion
by lidden (Curate) on Jul 24, 2009 at 09:36 UTC | |
by ikegami (Patriarch) on Jul 24, 2009 at 16:10 UTC |