http://www.perlmonks.org?node_id=1052332


in reply to Deep recursion on subroutine

If it takes long time to traverse the tree because of some time-consuming action you take on each node, you might want to write a lighter version of your crawler that does nothing but to traverse the tree. This is no guarantee that the 'real' thing will not hang but will give you some confidence.

You could also add some bookkeeping to make sure you have not visited a node already, for example because you have circular structures in the 'tree' that you were not aware of, or because of some bug.