jcpunk has asked for the wisdom of the Perl Monks concerning the following question:

I am much more familiar with C then Perl and was wondering if there is a perl equivalent to the
/*massively long multi line comment */
I looked around for one on the net but my searches returned nothing...

Replies are listed 'Best First'.
Re: multi line comments?
by LAI (Hermit) on Jun 16, 2003 at 20:08 UTC

    Generally speaking, there are no multiline comments in Perl. However, there are ways to cheat. And let me stress, that these are WRONG.

    1. pod
    POD is good. POD is sexy. But POD is for documentation, not comments. If you are evil, and don't care, you can use POD to add multiline comments. But don't do that.

    # Code does stuff here my $foo = 7; =pod I set $foo to 7 here because 7 is the number of God. Don't believe me? Well, then, $you eq 'numbskull'. So anyway, this multiline "comment" really shouldn't be here. =cut # more code here

    2. here documents
    This is even worse. Use a here document and assign it to a variable or, even worse, to nothing!
    Update: Note: Using the here document as I did will generate a warning. You do use the -w switch, right?

    print "foo = $foo \n"; <<'END_COMMENT'; And then we print $foo. By the way, make sure you use single quotes for this here document otherwise your @variables will wind up being interpolated. Except you shouldn't use this in the first place, so the point is moot. END_COMMENT

    Remember: don't do either of these things. Be content with one-line comments!

    I feel so dirty...

    print "All done! I'm a bad hacker! \n";

    LAI

    __END__
Re: multi line comments?
by broquaint (Abbot) on Jun 16, 2003 at 20:11 UTC
Re: multi line comments?
by sauoq (Abbot) on Jun 16, 2003 at 20:17 UTC
    wondering if there is a perl equivalent to the
    /*massively long multi line comment */

    None of the other options offered were actually comments, so they aren't equivalent. This is:

    # massively # long # multi # line # comment
    I know that's not the answer you are looking for, but I really recommend avoiding shortcuts on this issue.

    -sauoq
    "My two cents aren't worth a dime.";
    
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: multi line comments?
by particle (Vicar) on Jun 16, 2003 at 19:37 UTC

    there are many ways to do it. here are two:

    =pod long comment =cut
    if(0){ long comment }

    note: (thanks broquaint) the second method will fail to compile on syntax errors, so you might limit its use to comment out code that compiles properly.

    additionally, you might find the information in the perlpod perldoc handy.

    ~Particle *accelerates*

      You could modify the second method to:

      <<'COMMENT' if(0); long comment COMMENT

      bbfu
      Black flowers blossom
      Fearless on my breath

Re: multi line comments?
by Enlil (Parson) on Jun 16, 2003 at 20:13 UTC
Re: multi line comments?
by thelenm (Vicar) on Jun 16, 2003 at 20:09 UTC

    A useful thread is probably C style comments? which touches on this issue. Long and short of it, yeah, there are several ways to do multiline comments (POD, here-docs, q//, if(0){}), all of which work okay but most of which feel like nasty kludges. :-)

    -- Mike

    --
    just,my${.02}

Re: multi line comments?
by bluto (Curate) on Jun 16, 2003 at 20:38 UTC
    If this is a typing issue (i.e. it's a pain typing in '#' at the start of each line, and you'd like to reformat/reflow your comments on demand without having to add/remove the '#'s by hand), you may want to look into an editor that does most of this work for you. Emacs works well for me, but I'm sure others (e.g. vim) do this as well. Some editors also colorize comments which helps them stand out. For me, this solves 90% of the problem of not having multiline comments, and keeps me from doing stupid stuff (like accidently commenting sections of real code).

    bluto

      When editing perl code in vim, if you comment a line the following lines are commented, so you kind of get multi-line comments for free ;)
      If you want to comment a block of code, there are many plugins to do this, for example this one.

      hope this helps,

      update: first paragraph added, and rephrased second one.

        Of course besides plugins, you can use visual selection mode (:help visual) which is esp useful with the { and } keys to move paragraph-wise. You can either use I to insert the hashes at the front or something like :'<,'>s/^/# (the '<,'> is automatically added as soon as you type the double colon). Visual block selection mode (:help block) makes getting rid of the hashes a breeze - move cursor to top hash, Ctrl-v, } to jump to the end of the paragraph, adjust width of block if necessary, d.

        Makeshifts last the longest.

Re: multi line comments?
by thor (Priest) on Jun 17, 2003 at 04:22 UTC
    I'm rather partial to this:
    =for comment your comments go here =cut
    The first line designates it as a special directive for the "comment" pod reformatter. But, since there isn't one, it is ignored by all other pod reformatters. Plus, the word comment signals that it is, in fact, a comment.

    thor

Re: multi line comments?
by artist (Parson) on Jun 16, 2003 at 22:00 UTC
    Why can't you...
    How about seperating your code, so that you don't need to have comment more than 1 line per piece of code? :-)

    artist

Re: multi line comments?
by yosefm (Friar) on Jun 17, 2003 at 11:19 UTC
    I want to point out the difference between a ready (working or shared and not currently locked) script and a script-in-construction.

    If you're just testing something and need to leave out a section, there's nothing wrong with 'dirty' methods (as called above).

    On the other hand, when you're finished and it's working - do yourself and everyone else a favour by commenting properly with #.

Re: multi line comments?
by jacques (Priest) on Jun 17, 2003 at 05:13 UTC
    Larry Wall likes using pod, so we get pod. He's also married to a Latina, but do we get a sexy Latina thrown into the core? No, and where's the fairness in that?

    Yo quiero commentos multilino.