in reply to Block commenting

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.

Replies are listed 'Best First'.
Re: Re: Block commenting
by liz (Monsignor) on Nov 04, 2003 at 17:22 UTC
    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

      Personally, I think Acme::Comment lives in the wrong namespace: it should probably live in the Filter::Comment namespace or so.
      I disagree with that. I think that namespaces like Filter::* and Tie::* should be restricted to module that deal with filtering or tieing. It's just not right to make the implementation part of the name space. Just think about it, should all modules that use objects belong in the OO::* name space? And what are you going to do with a module that uses a filter, is hence named Filter::Whatever, and then modifies its implementation so that it uses a different technique?

      It's a bad, bad suggestion.

      Abigail

        Whatever. I think we agree that the Acme:: namespace is even more inappropriate.

        I personally don't care much where it winds up. Anything better than Acme::.

        Liz

      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.

      --

      flounder

      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 ;