简体   繁体   English

使用“ perl -c”验证语法,但忽略特定错误?

[英]Use “perl -c” to verify syntax but ignore a particular error?

I'm currently running perl -c filename to figure out whether the syntax of a file is alright. 我目前正在运行perl -c filename来确定perl -c filename的语法是否正确。 If it is, we can commit it to the VCS. 如果是这样,我们可以将其提交给VCS。

Now, some of the scripts to be checked have setuid bits set and this is perfectly alright. 现在,要检查的某些脚本已设置了setuid位,这完全可以。 According to perldiag this is why I get the warning: 根据perldiag这就是为什么我得到警告的原因:

Args must match #! line at /home/user/filename line 1.

How can I suppress the warning for a single run of perl -c ? 如何抑制一次运行perl -c的警告? The script has to be invoked with variable parameters, so I want to do a syntax check ignoring this issue - which is no real issue in the context. 必须使用可变参数来调用脚本,因此我想进行语法检查以忽略此问题-在上下文中这不是真正的问题。


Here's the reason I want to get rid of my filter script: it needs to literally count the output lines and then adjust the exit code depending on the count of relevant lines. 这就是我要删除过滤器脚本的原因:它需要从字面上计数输出行,然后根据相关行的计数来调整退出代码。 This is fairly tedious. 这是相当乏味的。


Some more details. 一些更多的细节。 Turns out the "warning" is actually an error to perl -c as can be seen in perldoc perldiag : 原来,“警告”实际上是perl -c的错误,如在perldoc perldiag可以看到的:

(F) A fatal error (trappable).
[...]
Args must match #! line
  (F) The setuid emulator requires that the arguments Perl was invoked with
  match the arguments specified on the #! line. Since some systems impose a
  one-argument limit on the #! line, try combining switches; for example,
  turn -w -U into -wU.

Please note this is a fairly old system ( Red Hat Linux release 7.3 (Valhalla) ) and a fairly old Perl ( Summary of my perl5 (revision 5.0 version 6 subversion 1) ...) 请注意,这是一个相当老的系统( Red Hat Linux release 7.3 (Valhalla) )和一个相当老的Perl( Summary of my perl5 (revision 5.0 version 6 subversion 1) ...)

Seems this error was deprecated in newer Perl versions. 似乎在较新的Perl版本中不赞成使用此错误。 I'll attempt to update the Perl version to see whether this is a feasible workaround. 我将尝试更新Perl版本,以查看这是否可行。

How about directing the output of perl -c through a filter that throws away the warnings you are not interested in (it finds these by regex). 如何通过过滤器引导perl -c的输出,该过滤器会丢弃您不感兴趣的警告(它通过正则表达式找到这些警告)。 Then, if you have any warning or error output left, you cannot commit to VCS. 然后,如果还有任何警告或错误输出,则无法提交到VCS。 If no such output left, commit to VCS. 如果没有这样的输出,请提交到VCS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM