Hey. Yeah deep recursion is something I don't really want to deal with. :) I've only used recursion once and that was to walk a data structure. For this kind of problem, which is a convergence problem, I would use a loop. I'm assuming that there is a variance value that is computed and compared to a tolerance value. When the variance is within tolerance, u have "the answer".
Here's what I would do: ($variance, $answer) = &solver($variance, $answer) while $variance > $tolerance; sub solver { my ($initvari, $initanswr) = @_; do { something; }; return ($curvari, $curanswr); } This gives u de facto recursion with the ease and sanity of iteration. HTH. At 02:02 PM 5/21/2009 -0700, gai...@visioninfosoft.com wrote: >given: > >a. that its generally considered to be 'bad form' to use global variables >inside of sub-routines. > >b. that I need to write a recursive sub-routine to solve a mathematical >problem. > > > >the sub-routine will recursively call itself until the 'answer' is derived. >when the innermost call finishes executing, the program will drop through to >the previous call, and so forth. until it drops out of the original first >call to the function. > > > >at present, I am 'cheating' here by using a global variable to control this >recursive behavior. when the innermost loop finds the 'answer', the global >variable is set to $weve_found_answer=1; > > > >the sub-routines then look to the value of $main::weve_found_answer to >determine if it should stop recursively calling itself because the answer >has already been found - or continue to recursively call itself again. > > > >for now it 'works' but its not following the 'don't use globals unless there >is no better way' principle. > > > >so I ask. 'is there a better way of allowing each sub routines >instantiation, at any nested level of the recursive call, be able to know >when the answer has been found?' > > > >if anyone has any insights or experience with this, I would be very >interested to learn from your experience > > > >thanks, greg > -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 00000100 _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs