in reply to Re: Re: Tail Recursion in Perl
in thread Tail Recursion in Perl

> I'm going to play newbie and ask you for an example of how you think goto &traverse_rec; is tail-recursive.

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.