How do I enter a multi-line comment in Perl? [duplicate]

我与影子孤独终老i 提交于 2019-11-27 09:16:53

问题


Possible Duplicate:
What are the common workarounds for multi-line comments in Perl?

How do I add a multi-line comment to Perl source code?


回答1:


POD is the official way to do multi line comments in Perl,
  • see Multi-line comments in perl code and
  • Better ways to make multi-line comments in Perl for more detail.

From faq.perl.org[perlfaq7]

  • How can I comment out a large block of Perl code?

The quick-and-dirty way to comment out more than one line of Perl is to surround those lines with Pod directives. You have to put these directives at the beginning of the line and somewhere where Perl expects a new statement (so not in the middle of statements like the # comments). You end the comment with =cut, ending the Pod section:

=pod

my $object = NotGonnaHappen->new();

ignored_sub();

$wont_be_assigned = 37;

=cut

The quick-and-dirty method only works well when you don't plan to leave the commented code in the source. If a Pod parser comes along, your multiline comment is going to show up in the Pod translation. A better way hides it from Pod parsers as well.

The =begin directive can mark a section for a particular purpose. If the Pod parser doesn't want to handle it, it just ignores it. Label the comments with comment. End the comment using =end with the same label. You still need the =cut to go back to Perl code from the Pod comment:

=begin comment

my $object = NotGonnaHappen->new();

ignored_sub();

$wont_be_assigned = 37;

=end comment

=cut



回答2:


I found it. Perl has multi-line comments:

#!/usr/bin/perl

use strict;

use warnings;

=for comment

Example of multiline comment.

Example of multiline comment.

=cut

print "Multi Line Comment Example \n";


来源:https://stackoverflow.com/questions/3828205/how-do-i-enter-a-multi-line-comment-in-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!