Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Better ways to make multi-line comments in Perl?

by kcott (Archbishop)
on Aug 22, 2015 at 21:02 UTC ( [id://1139551]=note: print w/replies, xml ) Need Help??


in reply to Better ways to make multi-line comments in Perl?

There's a variety of ways to add comments using POD.

Quick and dirty method to comment out some code:

=pod ... lines to comment out ... ... should be indented ... =cut

Adding a single line comment:

=for comment Some single comment line =cut ... =for comment Some single comment line =cut

Adding a multiline comment:

=for comment Some comment with multiple lines. =cut ... =for comment Some comment with multiple lines. =cut

Adding a multiblock coment:

=for comment lines from first block lines from next block ... lines from last block =cut

Replies are listed 'Best First'.
Re: Answer: Better ways to make multi-line comments in Perl?
by CountZero (Bishop) on Aug 23, 2015 at 19:14 UTC
    I have never seen anything wrong with
    # First comment # More comments # More comments # More comments # More comments # More comments # More comments # Last comment
    I find the # even rather aesthetically pleasing, whereas the empty line before =cut is quite ugly.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Answer: Better ways to make multi-line comments in Perl?
by Anonymous Monk on Aug 23, 2015 at 10:14 UTC

    Adding a multiblock coment: =for comment ....

    :) You meant "=begin comment ... =end comment", see perlpodspec

      Actually, either works. Didn't test correctly; used =begin comment ... =cut (which works) rather than =begin comment ... =end comment as AM proposed in Re: Answer: Better ways to make multi-line comments in Perl?. Fingers in gear; brain lagging behind.

      I found the =begin/=end format in http://perldoc.perl.org/perlpodspec.html#Pod-Commands\perlpodspec for 5.22 only under the heading "About Data Paragraphs and "=begin/=end" Regions" but ""=begin comment ... =end comment" does not work in AS 5.18.

      Granted, I'm mixing apples and ostrich eggs, above, but perlpod for 5.22 also appears (unless I'm misreading it) to suggest that =begin formatname/=end formatname and =for formatname... styles are for specialized cases only (see formatname, and not for run-of-the-mill comments.

        I see what you mean, =end doesn't signal to perl "pod over, perl code starts again", =cut does that, so it would have to be =begin comment ... =end comment\n=cut

        Using  =for multiblock comment has the unwanted side-effect of showing up if you use perldoc/pod2html...

        =pod/=cut has the same side-effect but that version is labeled quick/dirty

        If the intention is for #comments that aren't part of the documentation, =for comment multiline doesn't quite work for that purpose

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2025-01-20 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (59 votes). Check out past polls.