Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Better ways to make multi-line comments in Perl?

( #100344=categorized question: print w/ replies, xml ) Need Help??
Contributed by turumkhan on Jul 27, 2001 at 19:52 UTC
Q&A  > debugging


Description:

I know only one way of commenting in perl, and that is # ...
but that only creates a single-line comment. What if i want to comment out a block of code?
Are there any other ways to create comments?

Answer: Better ways to make multi-line comments in Perl?
contributed by arhuman

A good way is to use the POD system:

=pod die "testing"; =cut =for comment die "testing"; =cut

Also note - any decent code editor should enable you to throw a # in front of a selected set of lines very easily.

Answer: Better ways to make multi-line comments in Perl?
contributed by rob_au

I would add to this thread an interesting module which I found recently on CPAN, Acme::Comment - This source filter module allows for comments of many different styles to be incorporated into your code, including multi-line C++ style comments. For example:

use Acme::Comment type => 'C++'; /* This is a comment ... ... C++ style! */

Other commenting styles available through this module include - Fortran, HTML, LaTeX, Lisp and Pascal.

 

Answer: Better ways to make multi-line comments in Perl?
contributed by Abigail-II

The problem with just using a here document is that it will issue a warning under '-w'. It's much better to use the little known << >> operator.

<<q=~q>>; This is a multiline comment. q
Abigail
Answer: Better ways to make multi-line comments in Perl?
contributed by Anonymous Monk

Here's another style, that uses the C preprocessor:

#! /usr/bin/env perl -P #if 0 this is a multi-line comment #endif
Answer: Better ways to make multi-line comments in Perl?
contributed by Anonymous Monk

q^ In case you were wondering, this is a multi-line comment. ^ if 0;
Answer: Better ways to make multi-line comments in Perl?
contributed by roux.tophe

A "not-really-comment" that may be used also as a usage message...

my $comment= <<END_COMMENT this is how my script works and this is why it doesn't work blah blah END_COMMENT ; # don't forget the final ";"
... then usage function may print the $comment variable

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (11)
    As of 2015-07-07 19:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls