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

Is there any way to do block comments, like /* */ in C, that I have just been missing? And, if there is no real syntax for it, is there anything wrong with making an if(0) { } block around my code?

Replies are listed 'Best First'.
Re: C style comments?
by KM (Priest) on Aug 08, 2000 at 18:02 UTC
    use POD.

    my $I_am_some_code = qq{a value}; =cut Hi, I am a comment. Wow, now I am a multiline comment! =cut sub I_am_more_code { print $I_am_some_code; }

    The =cut directive will cut text out of code. Also look at perlpod.

    Cheers,
    KM

      Thanks, thats very helpful. I suppose its about time that I read up some more on POD. So much stuff to learn.... :)
RE: C style comments?
by jlistf (Monk) on Aug 08, 2000 at 18:07 UTC
    you can also use a here document. something like:
    my $variable = 1; <<Comment; la la la comments comments everywhere Comment print $variable;


    jeff
Re: C style comments?
by Maclir (Curate) on Aug 09, 2000 at 06:08 UTC
    What is wrong with:
    #!/usr/local/bin/perl -w # my $foo; #=================================# # This piece of code performs the # # bar transformation according to # # the algorithm in Chapter 8 of # # Knuth. # #=================================# sub bar { local $something = shift; # warning - tricky bit of code here # fixed on 9 Aug 2000 by KR to avoid # possible divide by 0 situation return 1; } # and so on
    That is the convention we use here, with most languages. Make the comments stand out, and be generous with them.

    Ken

      Sorry, I didn't make my intentions totally clear here: What I really wanted was a way to comment out a large block of code that I wanted to cut out for some reason - a lot of the time, I would find myself using an emacs macro to do it, but typing something like C-x ( C-n C-a # C-x ) C-u 50 C-e just to comment out a block of code is not too fun. Then I want to put it back in and have to go throught the whole thing again.

      I agree that the "lots o #'s" form is good for regular comments (read: information about the program), but slapping a few "=cut"s around code has been useful several times, just in the past day.

Re: C style comments?
by initself (Monk) on Dec 21, 2005 at 08:11 UTC
Re: C style comments?
by Happy-the-monk (Canon) on Dec 21, 2005 at 13:44 UTC
Re: C style comments?
by AgentM (Curate) on Aug 08, 2000 at 20:01 UTC
    No wait! There is nothing wrong with an if(0){} block! Perl recognizes code that can never be executed, may print a warning and scrap the code (i.e. not load it).
      Actually, there is something wrong with an if(0){} block: maintainability. As we work on programs and then come back to them months later, we often find that some slick hack that was obvious when we wrote it is difficult to understand when we come back. Further, if you work for a company where others have to maintain your code, they're not going to be too happy about seeing things like if(0){} scattered all over the place. Particularly for inexperienced programmers, it's not exactly intuitive that you'd using that to create a non-executing block.

      Cheers,
      Ovid