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__ | [reply] [d/l] [select] |
Re: multi line comments?
by broquaint (Abbot) on Jun 16, 2003 at 20:11 UTC
|
#!/usr/bin/perl -P
#if 0
insert comments here
#endif
See. perlrun for more info.
HTH
_________ broquaint | [reply] [d/l] |
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.";
| [reply] [d/l] [select] |
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
|
=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*
| [reply] [d/l] [select] |
|
|
<<'COMMENT' if(0);
long
comment
COMMENT
bbfu
Black flowers blossom
Fearless on my breath | [reply] [d/l] |
Re: multi line comments?
by Enlil (Parson) on Jun 16, 2003 at 20:13 UTC
|
| [reply] |
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}
| [reply] |
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
| [reply] |
|
|
| [reply] |
|
|
| [reply] |
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 | [reply] [d/l] |
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 | [reply] |
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 #. | [reply] |
Re: multi line comments?
by jacques (Priest) on Jun 17, 2003 at 05:13 UTC
|
| [reply] |