Re^2: Multi-line comments in perl code?
by TheDamian (Vicar) on Jul 14, 2006 at 13:33 UTC
|
The last item may change with Perl6, for "=begin/end", but the rest will probably not.
Actually, the first point:
POD is the official way to do multi line comments in Perl
will also change in Perl 6, which introduces an indentable, nestable, multi-line-able delimited comment:
#{ comment
here
}
#[ comment
here
]
#( comment here )
#< comment here >
#« comment etc. »
A delimited comment is introduced by a # followed immediately by any kind of opening bracket. It is closed by the corresponding closing bracket. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
#<<<
#<{[
because I could easily see myself wanting to comment out blocks of code with unbalanced closing brackets of all four types (or, more to the point, a dynamic selection of closing bracket types). Having an unlimited variety of comment "identifiers" also facilitates arbitrarily nesting comments without artificial restrictions.
We're building the house of the future together.
| [reply] [Watch: Dir/Any] |
|
Ow. Would it be too much to ask that it accept any sequence of opening brackets
Not to much to ask at all. At least, not as long as you can be satisfied with multiple repetitions of the same delimiter character. From the latest update of Synopsis 2:
| [reply] [Watch: Dir/Any] |
|
|
| [reply] [Watch: Dir/Any] |
|
Yay!++
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] |
Re^2: Multi-line comments in perl code?
by Anonymous Monk on Jul 13, 2006 at 17:58 UTC
|
Also you can always look at another Perl module and see how they document their code :) | [reply] [Watch: Dir/Any] |
Re^2: Multi-line comments in perl code?
by cxw (Scribe) on Apr 03, 2020 at 01:29 UTC
|
To clarify: as of writing, on Perl 5.28.1 and Perldoc v3.2801:
- =for comment hides text from perl but not perldoc
- =begin comment hides text from both perl and perldoc
For example, given foo.pl as follows:
=head1 SECTION
=for comment
Comment!
=cut
=begin comment
Comment! Number 2
=end comment
=cut
Therefore, I personally use =begin comment / =end comment / =cut, even though it's a bit tedious.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
=for comment
Comment!
=cut
... produces:
SECTION
Comment!
That is the correct behavior, your conclusion "=for comment hides text from perl but not perldoc" isn't correct. From perlpod (emphasis mine):
The command "=for formatname text..." specifies that the remainder of just this paragraph (starting right after formatname) is in that special format.
Remove the blank line after the =for and the "Comment!" is hidden. The =for still begins a section of POD that needs to be terminated by =cut, so Perl will ignore the entire example you posted.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re^2: Multi-line comments in perl code?
by aamailhot (Initiate) on Jan 04, 2017 at 20:36 UTC
|
It seems that the '=begin comment'/'=end comment' pair doesn't work inside of if-blocks, does anyone know if there is a fix for it?
E.g. the following code will fail to compile with a 'missing right curly' syntax error.
if(1==1) {
=begin comment
print "something else\n";
=end comment
print "hello!\n";
}
| [reply] [Watch: Dir/Any] [d/l] |
|
You're missing a "=cut" to end the POD.
| [reply] [Watch: Dir/Any] |