chunky5678 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that recursively calls itself. Inside of the recursive routine, there are several places (if statements using the return statement) for the code to return to the previous level of recursion and pick up to continue on with it's work. I am using Perl 5.05 on a Sun Unix platform.

The problem: It appears that if a return statement is executed inside of say for eaxmple 10 levels of recursion, it breaks out of all levels of recursion! I want it to go back to the previous level of recursion and the next statement after the calling of it's self.

I appreciate any help. TIA (Thanks in Advance)

Chunky

Replies are listed 'Best First'.
Re: Recursive Calling of a Function
by merlyn (Sage) on Sep 12, 2000 at 18:26 UTC
    The return operator does no such thing, so something is not as you say it is. Post a short snippet of code to demonstrate your understanding, and we'll be happy to explain it.

    -- Randal L. Schwartz, Perl hacker

Re: Recursive Calling of a Function
by little (Curate) on Sep 12, 2000 at 19:53 UTC
    mh, what about using named labels, and next label instaed of return, so u don't mess up in which call u are. ??
Re: Recursive Calling of a Function
by Anonymous Monk on Sep 12, 2000 at 23:31 UTC
    Could it be that a variable called within the function is being set as a global variable?
RE: Recursive Calling of a Function
by extremely (Priest) on Sep 13, 2000 at 07:41 UTC

    I agree with merlyn on this one, post your code.

    I'll also add on to what our Anonymous brother said and bet on it being a global that you are testing on to decide that if that returns. You are likely getting to a point where you set that global and explode out of every layer lickety-split.

    --
    $you = new YOU;
    honk() if $you->love(perl)