|
|
1
11
简单的答案是Perl::Critic在这里没有遵循PBP。这个 这本书明确指出,移位习语不仅是可以接受的,而且是可以接受的 实际上在某些情况下是首选的。 |
|
|
2
9
跑步
Always unpack @_ first at line 1, near
'sub xxx{ my $aaa= shift; my ($bbb,$ccc) = @_;}'.
Subroutines::RequireArgUnpacking (Severity: 4)
Subroutines that use `@_' directly instead of unpacking the arguments to
local variables first have two major problems. First, they are very hard
to read. If you're going to refer to your variables by number instead of
by name, you may as well be writing assembler code! Second, `@_'
contains aliases to the original variables! If you modify the contents
of a `@_' entry, then you are modifying the variable outside of your
subroutine. For example:
sub print_local_var_plus_one {
my ($var) = @_;
print ++$var;
}
sub print_var_plus_one {
print ++$_[0];
}
my $x = 2;
print_local_var_plus_one($x); # prints "3", $x is still 2
print_var_plus_one($x); # prints "3", $x is now 3 !
print $x; # prints "3"
This is spooky action-at-a-distance and is very hard to debug if it's
not intentional and well-documented (like `chop' or `chomp').
An exception is made for the usual delegation idiom
`$object->SUPER::something( @_ )'. Only `SUPER::' and `NEXT::' are
recognized (though this is configurable) and the argument list for the
delegate must consist only of `( @_ )'.
|
|
|
3
8
Perl Best Practices
全部的
就像这样--里面有很多东西是绝对必要的:使用
我试着遵循PBP中的大部分内容,但是Damian可以有我的子程序参数
至于Critic,您可以选择要实施的策略,甚至可以创建自己的策略(如果它们还不存在)。 |
|
|
4
3
-杰夫 |
|
|
5
0
我认为你应该避免换班,如果不是真的有必要的话! 刚遇到这样的代码:
使用unpacking my(…)=@@的一个直接好处是,您只需复制(…)部分并将其粘贴到调用该方法的位置,并且有一个很好的签名:)您甚至可以预先使用相同的变量名,而不必更改任何内容! 我认为shift意味着列表操作,其中列表的长度是动态的,您希望一次处理一个元素,或者显式地需要一个没有第一个元素的列表。但是如果您只想将整个列表赋给x参数,那么代码应该用my(…)=@;没人会怀疑。 |
|
|
Carsten · 使用最近的搜索模式更改文本块 1 年前 |
|
|
A.Ellett · 测试-t STDIN与-t<STDIN> 2 年前 |
|
|
con · 如何跳转到foreach迭代的特定点? 2 年前 |