Perl的常见陷阱?
关于
Hidden features of Perl的问题产生至少
one response,其可以被认为是特征或错误特征。跟进这个问题似乎是合乎逻辑的:在Perl中常见的非显而易见的错误是什么?似乎他们应该工作的东西,但不是。
我不会给出关于如何构造答案的指导方针,或者什么是“太容易”被认为是骗子,因为这是投票。 答案表 句法 >一般 > Single quotes instead of >文件句柄 > Heredoc notation when using print with lexical filehandles 语义/语言特性 >一般 > >上下文 > Assignment to scalar from arrays vs. lists >变量 > Can’t localize exported variables without exporting the entire typeglob 调试 > Warning: Use of uninitialized value in concatenation 最佳实践 > Forgetting to 元答案 > The perltrap manpage 参见:ASP.NET – Common gotchas 解决方法
事实上,单引号可以用于替换::在标识符中。
考虑: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |