I’d like perl -cw … to return a non-zero exit status if a compilation warning is emitted.
E.g. suppose a.pm is the file:
use warnings;
asd;
Then perl -cw a.pm reports:
Unquoted string "asd" may clash ...
Useless use of a constant in void context ...
a.pm syntax OK
and the exit status is set to 0. I’d like to be able to detect that compilation warnings were emitted – preferably though setting of the exit status.
Set a warning handler in a
BEGINblock (near the top of the script, so this block is parsed before the code that might trigger compile-time warnings), and tweak the exit status in anENDCHECKblock.The
$^Cvariable is true if and only if you have invokedperlwith the-coption.