Perl equivalent idiom for Python alert module

I need to port some code from Python to Perl. Python code makes it easy to use the warnings module, for example.

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

I searched quite a bit, but I don’t understand what the equivalent of Perl is. How does a Perl programmer handle this?

+4
source share
2 answers

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

 warn "Hey I'm a warning."; 

But you should also use the Perl warnings module, as well as strict , because they include all sorts of useful compiler warnings and error checking for you.

So start all your programs with

 use strict; use warnings; warn "Hey I'm a warning."; 

(You do not need the warnings module to use the warn function.)

+10
source

If you want something deeper than the simple warn function, you can use the Carp module. One of the especially nice things is that it allows you to print stacks with warnings or errors. Full documentation on the Perl website .

+2
source

Source: https://habr.com/ru/post/1496489/


All Articles