Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Answer: Better ways to make multi-line comments in Perl?
contributed by kcott

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
Answer: Better ways to make multi-line comments in Perl?
contributed by bharatt

Was having a bit of concern due to multi-line comment feature not readily available in perl.

Started to look-out for options and came across this post, and subsequently came to know the various ways we implement the multi-line comment.

Just took one of the options and slightly modified it and have been using it in way like a "defacto" standard in my scripts.

It was nice when i started to use it, and thought would share it.

--- multi-line comment syntax ---

q##//q# ... comments ... ... comments ... #;

--- example ---

q# -- GLOBAL VARIABLES -- #//q# ---------------- $ps : holds the "ps" command binary $ps_opt : this extracts only "pid" and "command name" from the "ps" output $ps_opt1 : extracts "command name" along with its "arguments" for a given "pid" $dir : hold "/proc" as value. This is the source directory from where the search for required informations for each pid starts $total_swap : stores the sum of swap usage of all the individual threads/processes @proc_swap : this array holds the "ref_arrays" in each of its index $PROC : is the file/command handle which holds the information of all the contents within "/proc" directory #;

-------------------

Thanks

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

Other applicable form :

q# comment_heading # // q# ... comment ... ... comment ... #;

"comment heading" -> is optional
space between "#" and "//" -> is optional

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

one more way :

' comment heading ' // ' ... comment ... ... comment ... ';

This will be bit more standardized as we might feel like using other characters instead of "#" along with "q" as shown above.
Single quote (') will help in maintaining uniformity while implementing multi-line comments.

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

a very simple way :

''//' ... comments ... ... comments ... ';
Answer: Better ways to make multi-line comments in Perl?
contributed by bharatt

Other applicable form

q# <comment heading> # // q# ... ... #;

<comment heading> => optional
space between "#" and "//" => optional

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 rifling through the Monastery: (10)
    As of 2015-08-30 14:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The oldest computer book still on my shelves (or on my digital media) is ...













      Results (349 votes), past polls