FAQ 7.27 How can I comment out a large block of Perl code?

Discussion in 'Perl Misc' started by PerlFAQ Server, Apr 16, 2011.

  1. This is an excerpt from the latest version perlfaq7.pod, which
    comes with the standard Perl distribution. These postings aim to
    reduce the number of repeated questions as well as allow the community
    to review and update the answers. The latest version of the complete
    perlfaq is at http://faq.perl.org .

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

    7.27: How can I comment out a large block of Perl code?

    (contributed by brian d foy)

    The quick-and-dirty way to comment out more than one line of Perl is to
    surround those lines with Pod directives. You have to put these
    directives at the beginning of the line and somewhere where Perl expects
    a new statement (so not in the middle of statements like the #
    comments). You end the comment with "=cut", ending the Pod section:

    =pod

    my $object = NotGonnaHappen->new();

    ignored_sub();

    $wont_be_assigned = 37;

    =cut

    The quick-and-dirty method only works well when you don't plan to leave
    the commented code in the source. If a Pod parser comes along, you're
    multiline comment is going to show up in the Pod translation. A better
    way hides it from Pod parsers as well.

    The "=begin" directive can mark a section for a particular purpose. If
    the Pod parser doesn't want to handle it, it just ignores it. Label the
    comments with "comment". End the comment using "=end" with the same
    label. You still need the "=cut" to go back to Perl code from the Pod
    comment:

    =begin comment

    my $object = NotGonnaHappen->new();

    ignored_sub();

    $wont_be_assigned = 37;

    =end comment

    =cut

    For more information on Pod, check out perlpod and perlpodspec.



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

    The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
    are not necessarily experts in every domain where Perl might show up,
    so please include as much information as possible and relevant in any
    corrections. The perlfaq-workers also don't have access to every
    operating system or platform, so please include relevant details for
    corrections to examples that do not work on particular platforms.
    Working code is greatly appreciated.

    If you'd like to help maintain the perlfaq, see the details in
    perlfaq.pod.
     
    PerlFAQ Server, Apr 16, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alec S.
    Replies:
    10
    Views:
    10,229
    Alec S.
    Apr 16, 2005
  2. Xah Lee
    Replies:
    3
    Views:
    566
    Jeff Shannon
    Jan 27, 2005
  3. Roseanne Zhang

    Can ruby comment out a block of code???

    Roseanne Zhang, Oct 14, 2006, in forum: Ruby
    Replies:
    5
    Views:
    156
    David Vallner
    Oct 15, 2006
  4. Dan Jacobson
    Replies:
    2
    Views:
    152
    Dan Jacobson
    Sep 20, 2003
  5. PerlFAQ Server
    Replies:
    0
    Views:
    120
    PerlFAQ Server
    Feb 3, 2011
Loading...

Share This Page