in reply to Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
But since you collect all found paths in memory (in @current), that array will get big pretty fast. So instead you should drop @current and print or save to file your found paths on success (inside your unless (defined $branches) ... and if (exists $regs... control structures. For this you need another parameter to your follow_paths subroutine that gives the momentary path to this point to the subroutine
So keep your recursive routine, it is much more readable, just save the results, if you can't keep them in memory.
But there is another possibility: Are you sure your data hasn't any loops, i.e. 0,1,0 points to 3,0,0 which points to 0,1,0 and both points are not in regs ? If there are loops you might put the points of your momentary path into a hash and call foul when you are at a point that already is in that hash.
|
|---|