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

Is there such a thing? It would be much handier to wrap long multi-line comments in such a structure than using #s at the beginning of each comment line.

Replies are listed 'Best First'.
Re: Perl equivalent of C-style
by Chmrr (Vicar) on May 24, 2002 at 19:01 UTC
Re: Perl equivalent of C-style multi-line comments
by virtualsue (Vicar) on May 24, 2002 at 20:08 UTC
    No, there isn't. A cheap way to get the same effect is to use Perl's POD (Plain Old Documentation) facility, but I would rather use my text editor to insert #'s at the beginning of all the lines in a block. Then it's absolutely obvious which lines are commented out.

    =pod Everything up to the cut is not parsed by perl print while @blah; my @slurp = <FH>; =cut
Re: Perl equivalent of C-style
by TheHobbit (Pilgrim) on May 24, 2002 at 20:32 UTC

    Hi,
    other monks have told you that such a thing as a multiline comment does not exist in Perl, but that you could do with someting like

    =for comment commented region =cut

    I would just had mi 5cents (of euro) to this. 'block' comments with a start and a stop delimiter, as /* and */ in C, are not (IMHO) a good thing©. Ever tryied to comment out using /* */ a region which already contained comments of its own? That's weird to do and even worst to undo...On the other had, til-the-end-of-the-line style comments are easy to use, with a good enough editor...

    Cheers


    Leo TheHobbit
Re: Perl equivalent of C-style
by Juerd (Abbot) on May 25, 2002 at 12:53 UTC

    Is there such a thing? It would be much handier to wrap long multi-line comments in such a structure than using #s at the beginning of each comment line.

    Acme::Comment

    My advice is to stick with #s.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: Perl equivalent of C-style
by Phemur (Beadle) on May 25, 2002 at 11:42 UTC
    I'm not a VI or Perl expert, but I seem to remember someone saying you could embed Perl in VI. If so, I'm guessing you could attach Perl scripts to a custom command. If that's the case, create two commands. Attach one to a script that adds block comments and the other to a script that removes them. Define your C-style comment delimiters (not /* */, since they tend to come up often in regex), then run the block comment script on the current file.

    The script runs through your file looking for a start comment delimiter. When it finds one, it puts a '#' in front of it, then one at the start of each subsequent line until an end comment delimiter is found. The remove block comment script does the opposite.

    There are a few other issues to solve, such as having an end delimiter in the middle of a line of code, or a line of code that was already commented before you ran the block comment script, but there are ways around these issues.

    I just made this up this morning. It's still too early for me to tell if this is a good idea or just something really silly. :-)

    Phemur

      No VI with embedded Perl needed. Or some convoluted procedure. Plain vi works without a problem:

      :.,+3s/^/#/

      This will put a # before the current line, and the next 3 lines.

      Or you could do something like:

      ;<<' */'=~m>>; /* * Multiline * comment. */