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...


Dave


In reply to Re: Re: Re: hash reference syntax? by davido
in thread hash reference syntax? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.