如何让 perl -c 抛出未定义或未声明的函数错误? [英] How do I get perl -c to throw Undefined or Undeclared function errors?
问题描述
来自 C++ 背景,我虔诚地使用 Perl 的 use strict
和 use warnings
特性:
Coming from a C++ background, I religiously use the use strict
and use warnings
features of Perl:
#!/usr/bin/perl -w
use strict;
use warnings;
$foo = 1; #Throws "$foo" requires explicit package name error
foobar( 1 );
use strict
结构对于在您输入错误的变量名时捕获错误非常有帮助.是否有等效的构造来捕获错误输入的函数名称?在上面的例子中,如果有类似 perl -c
的东西可以捕捉到没有 foobar 函数可以调用的事实,那就太好了.当然运行脚本会抛出一个未定义的子程序错误,但我想早点发现它.
The use strict
construct is immensely helpful to catch errors when you mistype a variable name. Is there an equivalent construct to catch mistyped function names? In the above example, it would be great if there was something like perl -c
that caught the fact that there is no foobar function available to call. Of course running the script throws an Undefined subroutine error, but I would like to catch it sooner.
推荐答案
试试这个:
perl -MO=Lint -cw /path/to/script.pl
这使用 B::Lint 模块.
这篇关于如何让 perl -c 抛出未定义或未声明的函数错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!