Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Multi-line comments in perl code?

by rodion (Chaplain)
on Jul 13, 2006 at 15:34 UTC ( #560985=note: print w/ replies, xml ) Need Help??


in reply to Multi-line comments in perl code?

I think it's useful to boil down what's already been said or referred to.

  • POD is the official way to do multi line comments in Perl, whether you think of it as as a work-around or not (which varies),
  • use "=for comment" or "=begin/end comment" for stuff that's just comments and shouldn't show up in the output text when documentation is extracted from the code, such as when you run perldoc on the program,
  • You can't indent the "=for comment", so it's not quite like other language's multiline comments, and
  • You do need a "=cut" at the end to get back to code. (I think this might be your main objection to using POD, and, yes, you're stuck with it).
The last item may change with Perl6, for "=begin/end", but the rest will probably not. See Apocalypse 2 RFC 5

Here's an example which you can runn with "perl" and with "perldoc" to see what shows up where. Note that in many places, such as before the "=cut", the blank line is part of the syntax.

=head1 tstcmt.pl This is text that shows up with the "perldoc tstcmt.pl" command. The comment sections below do not. =cut print "hello\n"; =for comment This is a single paragraph of comment text, spanning multiple lines. It ends with the first blank line. After that, the text is inuded with other printed pod text that shows up with perldoc This text also shows up with perldoc, it's not part of the "for" comment above. =cut print "hello1\n"; =for comment Another paragraph of comment text, spanning multiple lines. It ends with the first blank line. =cut print "hello2\n"; =begin comment This is a multi-paragraph comment section. Which is terminated by an =end comment on a line by itself. This is a second paragraph =end comment =cut print "hello3\n"; =head2 Other pod documentation This is text that also shows up with the "perldoc tstcmt.pl" command. The comment sections above do not. =cut print "hello4\n"


Comment on Re: Multi-line comments in perl code?
Download Code
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 :)
Re^2: Multi-line comments in perl code?
by TheDamian (Priest) 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.

      Ow. Would it be too much to ask that it accept any sequence of openingbrackets — e.g.

      #<<<
      #<{[
      
      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.
        If I read it correctly, Damian said, "It is closed by the corresponding closing bracket." [Emphasis added]

        So, the compiler ignores the non-corresponding closing brackets.

        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:
        • For all quoting constructs that use user-selected brackets, multiple, adjacent, identical opening brackets must always be matched by an equal number of adjacent closing brackets. Bracket counting naturally applies only to sets of brackets of the same length:
              say #{{
                  Comment contains unmatched } and { { { { plus a counted {{ ... }} pair.
              }} q<< <<woot>> >>   # says "<<woot>>"

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://560985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2014-07-28 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls