what does the Perl interpreter do when the stack is exceeded?
The stack won't overflow (though you could use up all available memory if things really get out of hand). However, Perl does issue a warning by default if you exceed some predetermined level of recursion. If I'm not mistaken, the predetermined level is decided upon when Perl itself is built for your particular system. In other words, you can increase the number if you want to rebuild your implementation of Perl.
Take a look at the following snippet... it should produce the warning, which on my system (and most implementations of Perl) occurs at the 100th level of recursion:
use strict;
use warnings;
sub recurse {
my $value = shift;
recurse ( $value - 1 ) if $value > 0;
print $value, "\t";
}
recurse( 99 );
And the output is: "Deep recursion on subroutine "main::recurse" at .....", followed by the list of recursion levels (that part is because of the snippet's print call).
You can turn off recursion warnings by saying "no warnings qw(recursion);" within the scope of your recursive function.
Hope this helps...
|