问题描述
提及
This RFC mentions
常见的解决方法是什么?
What are the common workarounds?
我发现两种技巧是
if (0) {
<comment>
}
和
=pod
<comment>
=cut
这些是否安全使用?有没有其他更好的工作?
Are these safe to use? Are there others that work better?
推荐答案
if解决方案的缺点是,注释掉的代码仍然必须编译(因此仍需要进行语法检查)。
The downside of the "if" solution is that the commented out code still has to be compiled (and therefore still has to be syntax checked).
您的pod解决方案的缺点是您的注释将出现在从pod生成的任何文档中。
The downside of your pod solution is that your comments will appear in any documentation generated from the pod.
我使用的pod解决方案没有这个问题的版本。 Pod supports = begin format ... =由特定格式化程序处理的结束格式段落。
I use a version of the pod solution that doesn't have that problem. Pod supports =begin format ... =end format paragraphs that are handled by specific formatters. I just invent a "comment" format that isn't handled by any of the formatters I use.
=begin comment
This is ignored by everything
=end comment
更新:
我错过了我的例子的一个重要部分。您需要使用= cut结束pod部分。这是一个完整的例子。
I missed an important part of my example. You need to end the pod section with =cut. Here's a full example.
#!/usr/bin/perl
print "This line is executed\n";
=begin comment
print "This line isn't\n";
=end comment
=cut
print "This line is\n";
这篇关于Perl中多行注释的常见解决方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!