Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello everybody,

I created a module in which I use the Tree module from CPAN, i.e.:

use Tree;

Since the trees I created with this module have extremely large depths, I noticed the module crashed with the following warning:

Deep recursion on subroutine "Tree::_fix_height" at /usr/lib/perl5/site_perl/5.10/Tree.pm line 334.

To solve this problem, I added the following line to the source of the Tree module:

no warnings 'recursion';

However, I don't like the fact that I have to edit source in order for this to work, so I was wondering whether there is a different solution for adjusting warning behaviour within external modules/packages..

Hope you are able to help!

Marinus

Replies are listed 'Best First'.
Re: How to turn off warnings in used (external) modules
by kennethk (Abbot) on Apr 02, 2010 at 15:47 UTC
    If you want to catch and treat the warning and error throwing behaviors of a submodule, you can use %SIG to write your own warn or die handler, as specified in the linked documentation. Something like:

    local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /recursion/};

    called before you start invoking tree crawling routines will locally suppress warnings containing the word 'recursion'. This, of course, assumes that you know, for a fact, that the warning is spurious.