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).

In reply to Re: Shortcut for inserting comments by graff
in thread Shortcut for inserting comments by ramthen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.