tags:

views:

151

answers:

3

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

Hi All,

I am new to Perl and am wondering how to do a multi-line comment.

A: 

I'm just editing my opinion - Perl supports multi-line comments - Ignore rest of this text


Perl doesn't support multi-line comments. You have to start each line with a '#' to comment that line.

#this is a comment

Note: The first line of a perl program is NOT a comment ( it's a directive which locates to the perl executable

#!/usr/local/bin/perl

So finally put, your program may look like this

#!/usr/local/bin/perl
#Program by XYZ created on September 30 2010...
print "Hello World\n";
Actually, the shebang line *is* a comment (as seen by perl). It is a directive to a hypothetical shell, if you use it to execute your perl script, so that the shell will know what to do it it.
Pedro Silva
Isn't it the kernel that interprets the shebang these days? Once upon a long time ago, it was the C Shell that did it (back in the days when Bourne shell scripts started with a ':' command). But that is a long, long time ago now.
Jonathan Leffler
@Pedro : - Sorry for the obvious mistake when I said "the first line .. is NOT a comment..". It's true that # is a comment as seen by perl.
+5  A: 

I found it. Perl has multi line comment

#!/usr/bin/perl

use strict;

use warnings;

=for comment

Example of multiline comment.

Example of multiline comment.

=cut

print "Multi Line Comment Example \n";
+8  A: 
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, you're 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
Nikhil Jain