Re: comment sections
by broquaint (Abbot) on Apr 15, 2003 at 09:11 UTC
|
s there a way to have perl ignore a big section without having to put comments in front of every row?
Stricly speaking, no, as # is the only of creating comments (natively) in perl. However you can use POD to comment out large sections like so
use strict;
=pod
...
=cut
exit 0;
However that won't work if you've got POD in the code inbetween. Another option is to use heredocs
use strict;
<<'IGNORETHIS';
...
IGNORETHIS
exit 0;
And finally there's always a CPAN module to do the job - Acme::Comment.
HTH
_________ broquaint | [reply] [d/l] [select] |
|
If you are going to use the here doc way, I suggest putting
single quotes around the delimiter; otherwise, Perl will
interpolate anything starting with a $ or a
@, which might cause warnings, or even compile
errors if you use strict.
Abigail
| [reply] [d/l] [select] |
|
=begin block_comment
...
=end block_comment
=cut
or for smaller chunks of code without blank lines in them a simple
=for consideration_later
.....
=cut
Doing it this way has the advantage that the pod'ed out code doesnt get treated by the various pod parsers as being part of the actual documentation.
---
demerphq
<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
| [reply] [d/l] [select] |
Re: comment sections
by Abigail-II (Bishop) on Apr 15, 2003 at 09:35 UTC
|
Get yourself a good editor! Here's how you would comment
out the current line, and the 65 lines following it in vi:
:.,+65s/^/#/
13 characters, including the trailing return.
Abigail | [reply] [d/l] |
|
| [reply] |
Re: comment sections
by davis (Vicar) on Apr 15, 2003 at 09:27 UTC
|
Just for silliness, I just had to post a link to Acme::Don't, which (IIRC) does the equivalent of wrapping a if(0) { ... } around your code. This implies that your code that you want to skip is compilable.
davis
It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
| [reply] |
Re: comment sections
by nite_man (Deacon) on Apr 15, 2003 at 09:29 UTC
|
You can use POD command for it:
#!/usr/bin/perl -w
use strict;
=head1 Name
=head1 Description
=cut
...
your code
=head2 Methods
=item method_1()
..... description
=cut
sub method_1 {
...
}
=item method_2 {
=cut
sub method_2 {
...
}
=back
=head1 AUTHOR
=cut
In this case, you will have both comments and documentation of your script or module.
Or if you use vim you can use its command for putting '#' in the lines which you define, but it's another story :-)
Cheers
--------------------------------
SV* sv_bless(SV* sv, HV* stash);
| [reply] [d/l] |
Re: comment sections
by Wookie (Beadle) on Apr 15, 2003 at 11:42 UTC
|
#!/usr/bin/perl -w
use strict; # Every job should
# Start of comments
if (defined undef) {
foo...
}
# End of comments
&do_more_stuff();
In terms of efficency - using a constant should kill a large block like that at compile time as opposed to run time (although the optimiser might take away the code in the solution above?).
#!/usr/bin/perl -w
use strict;
use constant COMMENT_WRAPPER => 0;
# Start comments
if (COMMENT_WRAPPER) {
Blah Blah
}
# End comments
&carry_on_with_stuff();
game(Wookie,opponent) eq 'Wookie' ? undef $problem : remove_limbs(arms,opponent); | [reply] [d/l] [select] |
|
But that requires that the stuff you outcomment is
actually compilable. And it won't help to outcomment
a BEGIN block.
Abigail
| [reply] [d/l] |
|
I vote for using #s as I've stated elsewhere under the heading no pod & code.
Personally I find the desire or need to temporarily
comment out
fair sized blocks of
code is a warning of impending danger or difficulty.
And usually these style of comments are meant to be
temporary. Often the trouble is so imminent that it
has already arrived.
Requiring commented code to be compilable seems like a
feature to me. But I know what you mean.
Quick update: The following is not what Abigail
said. Abigail pointed out that you can't comment the
entire BEGIN block this way. You can't. You
can't comment out any other subroutine definition either.
Or forward sub declaration.
And you can comment out code in a begin block. Viz:
#!/usr/bin/perl
use strict;
use warnings;
BEGIN { use constant COMMENT => 0; }
BEGIN {
if ( COMMENT ){
print "silence\n";
}
print "noise\n";
}
| [reply] [d/l] |
Re: comment sections
by h_golan (Initiate) on Apr 15, 2003 at 15:40 UTC
|
=pod
what ever u like
as long as u want
=cut
| [reply] [d/l] |