What I Learned Today      [ New Post ]

Thursday, August 25, 2005

Comment blocks in perl

There's no standardized builtin way to comment out a block of code in perl like there is in C.

In C:
/*
comment line 1
...etc...
comment line X
*/

In Perl:
# comment line 1
# ...etc...
# comment line X

Well, that doesn't work so well for a hundred lines you need to comment out, does it? So here's one way to do it...
my $comments=<<TOKEN
comment line 1
... etc ...
comment line X
TOKEN

Works like a charm, if a little wordy :( Fortunately, this stuff has been RFC'ed so I'm sure there will be a fix in the (near?) future.

2 Comments:

  • Actually I think you should use POD syntax.. It will confuse other developers less.. Like:

    =begin COMMENT

    I can make comments here. The cut statement is important.

    =end COMMENT
    =cut

    By Anonymous Anonymous, at 8:37 AM  

  • i find it's simplest to wrap everything in an if(0) block, ie.

    if (0)
    { # BEGIN COMMENT
    ...
    } # END COMMENT

    By Anonymous Anonymous, at 6:14 AM  

Post a Comment

<< Home