Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I comment out multiple lines in Perl?

In Perl, multi-line comments are also known as block comments and are defined using “=begin” at the start of the line and “=end” at the end of the comment line, and the other way of using block comments is by using quote operators q{}.

How do you add a comment in Perl?

Single line comments start with the # symbol. Block comments in Perl are enclosed within the = and =cut symbols. Everything written after the = symbol is considered part of the comment until =cut is encountered. There should be no whitespace following = in the multi-line comment.


POD is the official way to do multi line comments in Perl,

From faq.perl.org[perlfaq7]

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

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";