
johann_p
Novice
Apr 3, 2008, 11:49 AM
Post #1 of 1
(1023 views)
|
[Solved] Determine call within a recursion?
|
Can't Post
|
|
I have written a client function (realyl a closure) that gets called by some other perl program. That closure returns data to the program and gets called many times, sometimes from within a recursion. In other words, some function A in the program calls my closure, gets some data, and depending on the data the function A might get (indirectly) recursively called again, again calling the closure. In most cases, that is OK and will terminate. However, sometimes the data returned by the closure is erronous and leads to an infinite recursion of function A. The problem is, I cannot change function A or the program, just my closure. So -- is it possible to determine from within my closure that the call has come from function A after function A has recursively called itself already more than N times? EDIT: it seems I have found a solution: calling "caller($i)" with $i=1..N to figure out how often the function A is found on the stack.
(This post was edited by johann_p on Apr 3, 2008, 2:06 PM)
|