in reply to Infinite loop yet no loop

One, it's time to go back to basics: Comp Sci principles. Recursion needs a terminal case; some situation which you can PROVE will always happen eventually, that stops the recursion. In your case, all execution paths will reach the recursion call, even if $buffer is undef, or @$buffer is empty.
SOMECLASS->_addbuf($buffer) if $buffer && @$buffer;

Two, it's time to go back to basics: Debug by observation. Rather than infer that the program is spinning uselessly, you should either (1) run a debugger and WATCH the program do the unexpected, or (2) add print statements or other tracery so you can know exactly what's getting called, with what arguments, in what order, and when.

sub _addbuf { print STDERR "_addbuf(", Dumper(\@_), ")\n"; ... if (...) { print STDERR "making a new item...\n"; } }

Three, it's time to go back to basics. I don't know if you're just skipping parts of your example, but why are you creating a $new instance but never using it or attaching it anywhere?

(Don't take my tone as being angry or anything; it's easy to stare at code and forget to think about the basics of what you're trying to accomplish. We all do it. Well, everyone except for tye.)

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: Infinite loop yet no loop
by ido50 (Scribe) on Mar 21, 2004 at 15:44 UTC
    One - there is a terminating condition, I just didn't copy it, it didn't really matter as the recursion is not the cause of it...
    Two, I have tried some print statements, but couldn't find the problem. I'll try the debugger...
    Three, once again, I didn't copy the entire subroutine. I am using a check of $new to see if the node was shoved into the tree or not...

    Thanks to you and anyone who replied, I'll try all your suggestions.

    -------------------------
    Live fat, die young