gpt4 book ai didi

Perlcritic - 两个参数 "open"错误

转载 作者:行者123 更新时间:2023-12-04 16:20:37 26 4
gpt4 key购买 nike

我有一个脚本,我正在尝试使用 perlcritic 消除不良做法。

我的一行如下:

open(my($FREESPCHK), $cmdline ) || &zdie($MSG_PASSTHRU,"Error checking free space of file system.");

这给出了这个错误:
在第 xxx 行第 x 列使用的两个参数“open”。参见 PBP 第 207 页。 (严重性:5)

关于如何解决它的任何想法?

最佳答案

如果您使用 --verbose 11标志,您将获得更详细的错误解释。在这种情况下,您得到的错误如下所示:

Two-argument "open" used at line 6, near 'open FILE, 'somefile';'.
InputOutput::ProhibitTwoArgOpen (Severity: 5)

The three-argument form of `open' (introduced in Perl 5.6) prevents subtle bugs that occur when the filename starts with funny characters like '>' or '<'. The IO::File module provides a nice object-oriented interface to filehandles, which I think is more elegant anyway.

 open( $fh, '>output.txt' );          # not ok
open( $fh, q{>}, 'output.txt' ); # ok

use IO::File;
my $fh = IO::File->new( 'output.txt', q{>} ); # even better!

It's also more explicitly clear to define the input mode of the file, as in the difference between these two:

  open( $fh, 'foo.txt' );       # BAD: Reader must think what default mode is
open( $fh, '<', 'foo.txt' ); # GOOD: Reader can see open mode

This policy will not complain if the file explicitly states that it is compatible with a version of perl prior to 5.6 via an include statement, e.g. by having `require 5.005' in it.



我通过阅读 perlcritic 发现了这一点文档。

关于Perlcritic - 两个参数 "open"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8561008/

26 4 0
文章推荐: class - Haskell 类属性检查
文章推荐: session - 在 cakephp 2 中的行为中读取 session 变量
文章推荐: css - 是否可以折叠 CSS 缩放内容周围的外部
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com