Reputation: 3494
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?
Upvotes: 4
Views: 273
Reputation: 21
If you want something more in-depth than the simple warn
function, you can use the Carp
module. One of the particularly nice things about it is that it will let you print stacktraces with either warnings or errors. Full documentation available on the Perl site.
Upvotes: 2
Reputation: 66978
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.)
Upvotes: 9