例如.假设a.pm是文件:
use warnings; asd;
然后perl -cw a.pm报告:
Unquoted string "asd" may clash ... Useless use of a constant in void context ... a.pm Syntax OK
并且退出状态设置为0.我希望能够检测到发出了编译警告 – 最好是设置退出状态.
use strict; use warnings; my $warnings; BEGIN { $SIG{__WARN__} = sub { $warnings++; CORE::warn @_ } } $used::only::once = 42; CHECK { if ($^C && $warnings > 0) { exit $warnings; } }
当且仅当您使用-c选项调用perl时,$^C变量才为真.
$^C