in reply to Collecting data in a recursive routine.

Maybe I missing something here and if so, please just follup with what I am missing. You say ListCategories works. What is wrong with
  1. replacing the print with $output_string .=
  2. changing the function to this
    { my $output_string; sub DoListCategories { $output_string = ""; ListCategories(@_); } sub ListCategories { #Just as you had it with the change in 1 above } }
    Note the outer braces so $output_string is "private" to these two functions.
  3. Changing the calls in the main program from ListCategories to DoListCategories
This saves you from having to re-write working code.

HTH, --traveler

Replies are listed 'Best First'.
Re: Re: Collecting data in a recursive routine.
by Anonymous Monk on Mar 09, 2002 at 02:22 UTC
    I used your solution first because it seemed the most straight forward and required the least amount of change to my existing code.

    It worked perfectly and accomplished exactly what I wanted. The problem I had been running into was, indeed, that I was trying to be too "smart". From the moment I sat down to write the routine, I did it with the mindset that I'd accomplish everything in one sub which obviously was rediculous (now I see the error of my ways).

    I had suspected that doing what you suggested would work and may be the necessary way, but I also thought that there must be a standard solution to doing it all in one simple routine and that I was just too inexperienced to see it. Forest for the trees.

    Now that I at least have it working, I intend to go back and try implementing some of the changes the other posters above suggested for more efficiency, readability and flexibility.

    Thanks for the help!