in reply to Re: Re: Tail Recursion in Perl
in thread Tail Recursion in Perl
use warnings; sub recurse { my $i = shift; return if $i == 0; recurse($i-1); } sub tailless_recurse { my $i = shift; return if $i == 0; @_ = ($i-1); goto &tailless_recurse; } print "recursing\n"; recurse(200); print "tailless_recursing\n"; tailless_recurse(200);
This produces the following output:
recursing Deep recursion on subroutine "main::recurse" at /tmp/p line 7. tailless_recursing
Note that the second one doesn't produce the deep recursion warning.
|
|---|