The warning can be squelched easily enough. perllexwarn should identify which class of warnings to eliminate.
But the warning could be an indication of a bigger problem (and usually is). Imagine doing a traversal of a binary tree. A *balanced* tree with a million nodes would require 20 levels of recursion to traverse (assuming a recursive approach). Deep recursion warnings come after 100 levels of recursion, if I'm not mistaken. So either the algorithm being used is inefficient, or the tree isn't balanced, or there's a bug resulting in runaway recursion.
If the tree isn't balanced, it's probably time to start looking in the datastructure cookbook again. ;)
This isn't to say that there's no legitimate use of deep recursion; there is. But Perl isn't "tail call optimized", so when you start getting to the point that you're encountering deep recursion, an iterative approach would probably be more efficient anyway. An example: A linear search of a linked list can be written beautifully with recursion, but would hit the "deep recursion" warning with just 100 nodes. One could push on beyond that, but an iterative approach would expend fewer cycles on the linear search.
|