如何在Perl中注释单行的一部分,如下所示:
if($clevel==0){#never happends}
Run Code Online (Sandbox Code Playgroud)
我希望能够评论最后一个结束括号,而不需要换行.
lex*_*exu 11
该 #号开始,随着该行的末尾结束的注释.
mob*_*mob 10
如果真的那么重要,请使用源过滤.
# C_Style_Comments.pm
package C_Style_Comments;
use Filter::Simple;
FILTER { s{/\* .* \*/}{}gmx };
1;
Run Code Online (Sandbox Code Playgroud)
$ perl -MC_Style_Comments -e 'print /* 5, No wait, I mean */ 3'
3
Run Code Online (Sandbox Code Playgroud)
你不能写的任何理由:
if($clevel==0){#never happends}
Run Code Online (Sandbox Code Playgroud)
如:
if($clevel==0){} #never happens
Run Code Online (Sandbox Code Playgroud)
您可以使用一些技巧来隐藏消息,例如:
0 and 'some comment'
Run Code Online (Sandbox Code Playgroud)
但是,如果其他人不得不在将来维护您的代码,那么您只会让它变得更加混乱.
在语言的约束下工作,而不是试图强迫它像某种语言一样,你更熟悉,往往会让你学习新的东西.我个人讨厌在IDL工作,但是一些处理不良循环性能的技巧使我优化了自从用其他语言编写的代码.
A #然后换行.你可以将它们视为各种各样的支架,因为在Perl中很少会因为在不同的行上而失去意义.
my $ans = 2 + rand( 5 ) + $pixels / FUDGE_FACTOR;
Run Code Online (Sandbox Code Playgroud)
至
my $ans = # 2 +
rand( 5 ) + $pixels # / FUDGE_FACTOR
;
Run Code Online (Sandbox Code Playgroud)
或者来自:
if ( dont_know_how_this_breaks() && defined $attribute ) {
#...
}
Run Code Online (Sandbox Code Playgroud)
至:
if ( # dont_know_how_this_breaks() &&
defined $attribute ) {
#...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17447 次 |
| 最近记录: |