简体   繁体   中英

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. If it is, we can commit it to the VCS.

Now, some of the scripts to be checked have setuid bits set and this is perfectly alright. According to perldiag this is why I get the warning:

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

How can I suppress the warning for a single run of 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 :

(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) ...)

Seems this error was deprecated in newer Perl versions. I'll attempt to update the Perl version to see whether this is a feasible workaround.

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). Then, if you have any warning or error output left, you cannot commit to VCS. If no such output left, commit to VCS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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