Re: Block commenting
by duct_tape (Hermit) on Nov 04, 2003 at 16:29 UTC
|
=begin comment
code to comment out goes here....
=cut
| [reply] [d/l] |
|
Unless the blocks themselves contain POD. Or a here document
or string with \n=cut\s in it.
Abigail
| [reply] [d/l] |
|
I believe this is what I've seen ... Thanks!
| [reply] |
|
I also use POD to comment out blocks of code. I also never
leave those blocks in for long (or at least strive not to).
One trick i learned from merlyn is to be descriptive
with the POD and use something like:
=for comment
blah
blah
blah
=cut
But you are still going to interfere with any real
POD your code contains - which is why i strive to remove
unneeded code ASAP and let CVS handle the history (but i
still leave phantom code from time out of false laziness).
| [reply] [d/l] |
Re: Block commenting
by thraxil (Prior) on Nov 04, 2003 at 16:21 UTC
|
either get a decent text editor that will let you comment an entire region at once, or do something quick and dirty like:
if(0) {
...
}
| [reply] [d/l] |
|
Unfortunetly, we all don't get to work with just any text editor. I'm stuck with what they give me, but I do like your other suggestion. Thanks!
| [reply] |
|
| [reply] |
|
| [reply] [d/l] |
Re: Block commenting
by Abigail-II (Bishop) on Nov 04, 2003 at 16:23 UTC
|
POD, here docs, strings, Acme::Comment, smart editors,
editor macros, it all works. Take your pick.
Abigail | [reply] |
|
To complete that list, and for no other reason, I will mention #if 0/#endif with perl's -P switch.
| [reply] [d/l] |
Re: Block commenting
by Roger (Parson) on Nov 04, 2003 at 16:20 UTC
|
Why not try to wrap your code inside a dummy heredoc assignment, say,
my $dummy = <<'COMMENT'
... your code here ...
...
...
COMMENT
;
or just
# was << COMMENT
<<'COMMENT'
... your code block here ...
...
...
COMMENT
;
Which will comment out a block of code.
Update: Thanks to liz for pointing out the problem with my initial un-single-quoted HEREDOC. I have improved the solution by adding a single quote around the COMMENT. However this solution is still flawed - see flounder99's post below.
| [reply] [d/l] [select] |
|
Not a very good idea, as the comment still is interpolated:
use strict;
<<COMMENT;
$foo = 'bar';
COMMENT
gives:
Global symbol "$foo" requires explicit package name at line 3.
Abigail-II's suggestion of Acme::Comment is pretty serious, if you really want to have multi-line comments the way you want them. Personally, I think Acme::Comment lives in the wrong namespace: it should probably live in the Filter::Comment namespace or so.
Liz | [reply] [d/l] [select] |
|
| [reply] |
|
|
|
use strict;
use warnings;
<<'COMMENT';
$foo = 'bar';
COMMENT
Will avoid the interpolation. But you will still get
Useless use of a constant in void context at temp.pl line 3.
To avoid that you can do:
use strict;
use warnings;
{
no warnings;
<<'COMMENT';
$foo = 'bar';
COMMENT
}
But that is a lot of work.
| [reply] [d/l] [select] |
|
Thanks++ for pointing out that the comment is interpolated. However to fix this, I would simply add single quotes around the COMMENT to prevent the HEREDOC to be interpolated.
use strict;
<<'COMMENT'
$foo = 'bar';
COMMENT
;
| [reply] [d/l] |
Re: Block commenting
by matthewb (Curate) on Nov 04, 2003 at 16:23 UTC
|
You haven't seen multiline commenting (in the sense that you describe) in a Perl program but it is feasible to me that you recall seeing some POD somewhere and remember it as a comment. Check perlpod for a refresher.
I find it helpful to bind cperl-comment-region to a handy key in emacs - that way block-commenting is only ever a couple of keystrokes away.
MB | [reply] |
Re: Block commenting
by hardburn (Abbot) on Nov 04, 2003 at 16:48 UTC
|
I use the vim block comment script. I changed the commands to use the comma key instead of the period, or else it tends to sit there waiting for you to type something more when you want to repeat the last command.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] |
Re: Block commenting
by Anonymous Monk on Nov 05, 2003 at 07:58 UTC
|
| [reply] |