It's good (better/best) to use return statement in recursive code!#factorial through recursion use strict; use warnings; print "enter number\n"; my $num=<>; my $fac = &fact($num,1); print "factorial: $fac\n"; ################## sub fact { my($num1,$flag)=@_; if($num1==0) { return $flag; # print "$flag" and die "brrrrrrrreeeeeee :D\n"; } else {fact($num1-1,$num1*$flag);} }
In reply to Re: factorial through recursion
by imrags
in thread factorial through recursion
by hnd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |