Perlcritic - 两个参数“开放"错误 [英] Perlcritic - Two argument "open" error
问题描述
我有一个脚本,我正在尝试使用 perlcritic 消除不良做法.
I have a script and I am trying to elimate bad practices using perlcritic.
我有一行如下:
open(my($FREESPCHK), $cmdline ) || &zdie($MSG_PASSTHRU,"Error checking free space of file system.");
这给出了这个错误:在第 xxx 行第 x 列使用的两个参数open".参见 PBP 第 207 页.(严重性:5)
This gives this error: Two-argument "open" used at line xxx, column x. See page 207 of PBP. (Severity: 5)
关于如何修复它的任何想法?
Any ideas on how to fix it?
推荐答案
为了让 Perl Critic 闭嘴,但并没有真正的好处,只需将代码修改为:
To make Perl Critic shut up, but do no real good at all, just modify the code to:
open(my $PIPE_FROM_FREESPCHK, "-|", $cmdline)
|| zdie($MSG_PASSTHRU, "Error checking free space of file system.");
但是请注意,这与更明显的相比在任何方面都没有更好:
Note however that this is absolutely no better in any regard whatsoever from the far more obvious:
open(my $PIPE_FROM_FREESPCHK, "$cmdline |")
|| zdie($MSG_PASSTHRU, "Error checking free space of file system.");
因为您没有分离出用于直接调用 exec
的令牌.看起来更像这样:
Because you are not separating out your tokens for calling exec
directly. That would look more like this:
open(my $PIPE_FROM_FREESPCHK, "-|", $cmd_name, @cmd_args)
|| zdie($MSG_PASSTHRU, "Error checking free space of file system.");
问题在于您是在运行 shell 命令还是只是在执行某些操作.如果您的免费支票类似于 df .2>/dev/null |awk ....
,那么你需要完整的shell.如果它仅仅是<代码>东风的,那你就不要.
The question is whether you are running a shell command or just exec’ing something. If your free check is something like df . 2>/dev/null | awk ....
, then you need the full shell. If it is just df
, then you don’t.
这篇关于Perlcritic - 两个参数“开放"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!