perl - 如何检查 Perl 脚本是否有任何编译错误?

标签 perl compilation

我在 Bash 脚本中调用许多 Perl 脚本(有时也从 csh 调用)。

在 Bash 脚本的开头,我想进行一个测试,检查所有 Perl 脚本是否没有任何编译错误。

一种方法是从 Bash 脚本中实际调用 Perl 脚本,并在管道日志文件中调用 grep 来查找“编译错误”,但这会变得困惑,因为调用了不同的 Perl 脚本在代码中的不同点,所以我想在 Bash 脚本的一开始就执行此操作。

有没有办法检查Perl脚本是否有编译错误?

最佳答案

小心!!

使用以下命令检查 Perl 程序中的编译错误可能很危险。

$ perl -c yourperlprogram

Randal 就这个主题写了一篇非常好的文章,您应该看看

引用他的文章:

Probably the simplest thing we can tell is "is it valid?". For this, we invoke perl itself, passing the compile-only switch:

perl -c ourprogram

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:

BEGIN { warn "Hello, world!\n" } 

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:

BEGIN { system "rm", "-rf", "/" } 

and you'll see the problem with that argument. Oops.

关于perl - 如何检查 Perl 脚本是否有任何编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12908416/

相关文章:

javascript - 在 Perl CGI 脚本中捕获 iframe 返回值

perl - 我如何在Perl中获得本周的日期?

objective-c - 为什么在针对 ios 5 应用程序时使用特定于 ios 6 的选项仍然可以编译或不会崩溃?

c - 使用 QtCreator [mac os] 找不到 -lrt 的库

perl - 如何删除 Perl 中的 CGI 默认元字符集编码?

MySQL 搜索单词中带有 $ 的精确单词

检查文件是否是c文件并编译它

c++ - 使用#ifndef 时具体定义了什么

linux - haskell 中的 Latexpdf 式功能?

perl - xml 格式变化时的 xpath 查询