Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Thursday January 16, 2003
11:51 AM

Deep recursion

[ #10016 ]

The most interesting exerise answer I have ever received from a Learning Perl student got stung by deep recursion.

The exercise asked the student to write a subroutine to add numbers. I like the answer:

sub total
    {
    if( ! @_ )
        {
        return 0;
        }
    shift(@_) + total(@_);
    }

This worked fine for the short lists in the problem, but the next problem asked the student to use the subroutine to add the numbers 1 to 1000. Around 100 levels of recursion the program blew up.