在Bash脚本的开头我想要一个测试,检查所有的Perl脚本是否没有任何编译错误。
这样做的一种方法是从Bash脚本调用Perl脚本,并在管道日志文件中调用grep for“编译错误”,但是由于不同的Perl脚本在代码中的不同点被调用,所以我变得很乱。在Bash脚本的开头做到这一点。
有没有办法检查Perl脚本是否没有编译错误?
解决方法
使用以下命令检查Perl程序中的编译错误可能很危险。
$ perl -c yourperlprogram
兰德尔写了一个很好的文章,你应该检查这个话题
> Sanity-checking your Perl code(Linux Magazine Column 91,2007年3月)
引用他的文章:
Probably the simplest thing we can tell is “is it valid?”. For this,
we invoke perl itself,passing the compile-only switch:06001
For this operation,perl compiles the program,
but stops just short of the execution phase. This means that every
part of the program text is translated into the internal data
structure that represents the working program,but we haven’t actually
executed any code. If there are any Syntax errors,we’re informed,and
the compilation aborts.Actually,that’s a bit of a lie. Thanks to BEGIN blocks (including
their layered-on cousin,the use directive),some Perl code may have
been executed during this theoretically safe “Syntax check”. For
example,if your code contains:06002
then you will see that message,
even during perl -c! This is somewhat surprising to people who
consider “compile only” to mean “executes no code”. Consider the
code that contains:06003
and you’ll see the problem with that argument. Oops.
@H_404_51@