Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Deep recursion problem

by davido (Archbishop)
on Oct 21, 2011 at 17:05 UTC ( #932937=note: print w/ replies, xml ) Need Help??

in reply to Deep recursion problem

Turning on use diagnostics; will give you a more meaningful warning, which may explain why there is a warning when you reach 100:

Deep recursion on subroutine "main::recurse" at line 11 (#1) (W recursion) This subroutine has called itself (directly or indirectly) 100 times more than it has returned. This probably indicates an infinite recursion, unless you're writing strange benchmark programs, in which case it indicates something else.

This threshold can be changed from 100, by recompiling the perl binary, setting the C pre-processor macro PERL_SUB_DEPTH_WARN to the desired value.

Keep in mind that recursion is often seen as a simple means of traversing a binary tree or doing binary searches; O(log n) operations for balanced trees. A tree size would have to be greater than 2.7e43 elements for you to reach the recursion max warning in an efficiently designed recursive tree-traversal or binary search algorithm. ...and when you exceed that many function calls on the call stack the speed of an iterative approach begins to weigh in favorably against recursion. Recursion can be used for many other things though, so Perl lets you lift the warning.


Comment on Re: Deep recursion problem
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932937]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2015-11-26 16:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (701 votes), past polls