Search code examples
bashperlcron

How to stop perl message "XXX is deprecated use YYY instead" from going to stderr?


System:

  • Ubuntu 18.04 with Perl 5.26.
  • I use alpine for email to get emails from cron, which are mainly messages that go to stderr.
  • Searching web pages yielded no answers. So here I am.

Situation:

  • I have a main Perl program, which is like a listserv program, which logs into an email account and processes email commands in each email, and determines which program to run based on commands in an email. Both the listserv like program and the called program use a list of my library routines called util2.pl. util2.pl has to use Mail::Sender as I could not get a newer email sending program to work in our Perl, even after searching for pages, etc. So for now, we have to use Mail::Sender.
  • util2.pl is included in every program in the chain via require /path/to/util2.pl.
  • I run the listserv-like program, which checks email, via a bash file and cron. So every time the bash file runs the listserv-like program, I get this error message going to stderr "Mail::Sender is deprecated...".
  • In my bash file run by cron I've tried perl /path/to/program.pl bunch of arguments 2>/tmp/stderr.txt but I still get an email from cron with this error messages. That is, I get an email with this error message every 10 minutes of every day of the week. I end up with thousands of emails with this message.

Questions:

  1. How do I get this message to stop being output? Is there a perl setting to prevent this one message? I'd like other messages to pop up like if I have an undefined variable, something is doing a numeric comparison on a non-numeric variable, etc. I would just like to disable this one "blah is deprecated" message going to stderr.
  2. Or, can I set up some kind of filter to delete any messages with the error message in it? I don't know anything about filters in alpine.

Thank you so much, this has been quite a headache for me.


Solution

  • The warning comes from this line:

    warnings::warnif('deprecated', 'Mail::Sender is deprecated and you should look to Email::Sender instead');
    

    If you look into warnings, you'll see that a category can be turned off by

    no warnings 'deprecated';
    

    So, wrap the use Mail::Sender into

    {   no warnings 'deprecated';
        use Mail::Sender;
    }
    

    Or directly comment out the line.

    The correct solution would be to switch to Email::Sender, though. Whatever hack you implement, consider and plan a real fix, which is to stop using the deprecated library.