When you say "input redirection characters", are you talking about the "HEREDOC" syntax? e.g.:
#!/usr/bin/perl
use strict;
use warnings;
my $first_try;
my $commented_out = <<ENDCOMMENT;
if( $first_try ) {
print "this part of my code is experimental\n";
my $message = "it's not ready to be treated as executable yet";
# do stuff with $message...
}
ENDCOMMENT
print "@ARGV\n";
That won't work because any "my" declarations inside the HEREDOC will not be recognized as such, and the script will not compile with use strict.
Another way is to use an always-false "if":
if (0) {
# lots of code here that I don't want to use just now...
}
This way, the code needs to be well-formed in order for the script to compile (bracketing and quotes must be balanced, lexical-scope variables must be declared), but it's fairly effective if your code is already pretty well organized.
A third way is to use POD directives:
# this part is currently runnable:
my $foo = "bar\n";
=head2 Commented out
my $baz = "blah";
# lots more code that I don't want to use right now...
=cut
# this part is also currently runnable...
print $foo;
In this case, the stuff within the POD-commented region doesn't need to be syntactically well-formed -- anything goes. Here, the only issue to worry about is if you happen declare subroutines or lexical variables within the commented region, and then try to use them outside that region -- that's a problem for all approaches, but it's the only problem in the POD approach. Again, if your code is already well-organized, this shouldn't be too much of a problem.
That said, I think most good programming editors have a "comment-region" type of command or macro (as well as "uncomment-region") that knows how to put (remove) "#" at the beginning of every line in a selected region of text.
Another trick -- if you know the line numbers, or if the start and end line content are sufficiently unique, you can stream-edit the script with perl:
perl -i.bak -pe '$_="# $_" if($.>=10 and $.<=20)' myscript.pl
(comment lines 10-20 inclusive), or:
perl -i.bak -pe '$_="# $_" if(/^\$foo =/../^\$bar =/)' myscript.pl
(comment lines starting with "$foo = ..." and ending with "$bar = ...", inclusive). |