Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932937]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-02-25 21:27 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (369 votes). Check out past polls.