in reply to Re: Scoping problems with recursive function
in thread Scoping problems with recursive function

[Prototyping is] unnecessary in Perl unless you are doing particular tricks and probably doesn't mean what you think it means.

I strongly agree. However...

... you need cleverness to protoype a function you are calling recursively.

But not very much cleverness. All that's needed is to declare (or define) the function before it's invoked:

>perl -wMstrict -le "sub fact ($); # function declaration print qq{$_! == }, fact($_) for 0 .. 5; sub fact ($) { # function definition my $n = shift; return $n > 1 ? $n * fact($n - 1) : 1; } " 0! == 1 1! == 1 2! == 2 3! == 6 4! == 24 5! == 120

Note: If you want to run the example above in Windose, first remove the # comments!