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:
In reply to Re: factorial through recursion
by ikegami
in thread factorial through recursion
by hnd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |