G'day Yary,

"I have this memory of Perl limiting how deep subroutine recursion could go, ..."

Perl only warns when a certain recursion depth is reached; it doesn't prevent you from recursing deeper.

"... but the following test suggests not:"

If you ask for warnings, you get them:

$ perl -E 'sub f{say $_[0] unless $_[0] % 10000;exit if $_[0] > 30000; +f($_[0]+1)};f(1)' 10000 20000 30000 $ perl -wE 'sub f{say $_[0] unless $_[0] % 10000;exit if $_[0] > 30000 +;f($_[0]+1)};f(1)' Deep recursion on subroutine "main::f" at -e line 1. 10000 20000 30000
"Just curious if there was a recursion limit, ..."

The limit is 100, i.e. on the 100th recursion, a warning is emitted.

$ perl -wE 'sub f{say $_[0] unless $_[0] % 33;exit if $_[0] >= 99;f($_ +[0]+1)};f(1)' 33 66 99 ken@ganymede: ~/tmp $ perl -wE 'sub f{say $_[0] unless $_[0] % 33;exit if $_[0] >= 100;f($ +_[0]+1)};f(1)' 33 66 99 Deep recursion on subroutine "main::f" at -e line 1.

Search for "Deep recursion on subroutine" in perldiag for more details and additional information.

Also, if you're using the warnings pragma, which I strongly recommend, you can selectively turn off warning messages.

— Ken


In reply to Re: No recursion depth limit? by kcott
in thread No recursion depth limit? by Yary

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.