CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
[Solved] Determine call within a recursion?



Apr 3, 2008, 11:49 AM

Post #1 of 1 (1171 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)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives