Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl equivalent idiom for Python's warnings module

I need to port some code from Python to Perl. The Python code makes simple use of the warnings module, e.g.

warnings.warn("Hey I'm a warning.")

I've been googling around quite a bit but it's unclear to me what the equivalent Perl idiom might be. How would a Perl programmer handle this?

like image 978
elhefe Avatar asked Dec 15 '22 07:12

elhefe


1 Answers

To write a message to STDERR, simply use the built-in warn function.

warn "Hey I'm a warning.";

But you should also use Perl's warnings module, as well as strict because they turn on all kinds of useful compiler warnings and error checking for you.

Therefore, begin all your programs with

use strict;
use warnings;

warn "Hey I'm a warning.";

(You don't need the warnings module to use the warn function, though.)

like image 184
friedo Avatar answered Dec 27 '22 22:12

friedo