Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to find a substitue to remarking half a script with # on each line. Can I do something on just the first and last lines?

Replies are listed 'Best First'.
Re: Remarks
by chromatic (Archbishop) on Jun 13, 2000 at 04:48 UTC
      To make the best use of this (POD directives) you need an editor that does syntax highlighting. Otherwise there is a chance that you will think you are in the middle of real code when really you are in comments. At least with a # on every line there is less chance of that. If you are using vi/gvim as your editor I'm pretty sure that you could insert the comment character at the front of a range of lines with something like:

      'a,'b s/^/#/

      Where a and b are the marked start and end positions of the range.
(jcwren) Re: Remarks
by jcwren (Prior) on Jun 13, 2000 at 04:41 UTC
    You can use the -P option, which runs the source through the 'C' preprocessor before submitting it to the Perl compiler. If you do this:
    use strict; { print "This is a line of text\n"; #if 0 print "This will not print\n"; #endif }
    only the first print statement will execute. Invoke with  perl -P myscript.pl --Chris
Re: Remarks
by kirbyk (Friar) on Jun 13, 2000 at 21:57 UTC
    Even simpler, though less efficient (thus, ideal for testing) is to do something like:
    Useful stuff.... if (0) { #Added to 'comment' things out Stuff to ignore Could be a lot } #End comment if

    Obviously, there's a danger that you can screw yourself up if you don't comment this sort of thing, but for quick-n-dirty code testing, it'll do.

    -- Kirby

    Tuxtops: Laptops with Linux!

RE: Remarks
by osfameron (Hermit) on Aug 07, 2000 at 03:05 UTC
    I read another solution to this by Tom Christiansen in the Perl6 language discussion:
    sub comment($) { } comment <<"END OF FIRST COMMENT"; asdf asdf asdf asdf asdf END OF FIRST COMMENT
    The ($) prototype means that comment expects to be passed a scalar, e.g. the result of the "HERE" document (everthing between the <<"END OF FIRST COMMENT" and the END OF FIRST COMMENT markers).

    Cheerio!
    Osfameron

      It is amusing to see Tom Christiansen not taking his own IMHO excellent advice. For those who do not want to learn exactly what Perl's prototypes are, how to use them, what they can do, and what the problems with them are, the one line summary is that, "Prototypes were a misfeature of the day."