我不会给出关于如何构造答案的指导方针,或者什么是“太容易”被认为是骗子,因为这是投票。
答案表
句法
>一般
> Single quotes instead of ::
in identifiers
> Indirect object syntax
> Confusing references with plain var types
>文件句柄
> Heredoc notation when using print with lexical filehandles
> Printing to a lexical filehandle contained in a hash
> my
declarations should use parens around lists of variables
> Comparing strings with == and !=
语义/语言特性
>一般
> do
is not a loop. You cannot next
.
> Using the /o modifier with a regex
> Forgetting that readdir
‘s results are not relative to the CWD
> Unary minus’s interaction with strings
>上下文
> Assignment to scalar from arrays vs. lists
> The glob() iterator(另一个问题)
> Implicit returns in list context
> Parenthesis changing the semantics of operators
> Calling context is propagated to return statements within functions
>变量
> Can’t localize exported variables without exporting the entire typeglob
> Using multiple variables (of different types) with the same name
> while <FH>
does not localize $_
automatically
> The Variable That’s Validly Zero
> Constants can be redefined
调试
> Warning: Use of uninitialized value in concatenation
最佳实践
> Forgetting to use strict
and use warnings
(or use diagnostics
)
> @L_403_25@(即,再次使用strict)
元答案
解决方法
考虑:
use strict; print "$foo"; #-- Won't compile under use strict print "$foo's fun!"; #-- Compiles just fine,refers to $foo::s
导致以下问题:
use strict; my $name = "John"; print "$name's name is '$name'"; # prints: # name is 'John'
print "${name}'s name is '$name'"; # John's name is 'John'
还要使用警告,因为它会告诉你使用未定义的变量$ name :: s