Perl warnings and the warn function
I mentioned in passing last week that the next major release of Perl, v5.36, is set to enable warnings
by default for code that opts in to use v5.35;
or above. Commemorating Perl’s 34th birthday the week before that, I noted that the warnings system has been getting ever finer-grained since its introduction in 2000. And fellow Perl blogger and CPAN author Tom Wyant has been cataloging his favorites over the past several months — the latest as of this writing was on the “ambiguous” category of warnings, and you can find links to previous entries in his series at the bottom of that post.
It occurred to me afterward that there may be some confusion between the warnings
pragma and the related warn
function for reporting arbitrary runtime errors. warn
outputs its arguments to the standard error (STDERR
) stream, or if it’s not given any then you get a string with any exception from $@
($EVAL_ERROR
under use English
) followed by a tab and then “...caught at <file> line x.
” If that’s empty too, a plain warn
just says, “Warning: something's wrong at <file> line x.
”, which isn’t exactly helpful, but then again you didn’t give it much to go on.
warn
output doesn’t have to go to STDERR
, and this is where the relation to the warnings pragma comes in because both are governed by the __WARN__
signal handler in the %SIG
…