in reply to Better ways to make multi-line comments in Perl?

The problem with just using a here document is that it will issue a warning under '-w'. It's much better to use the little known << >> operator.
<<q=~q>>; This is a multiline comment. q
Abigail

Replies are listed 'Best First'.
Re: Answer: Better ways to make multi-line comments in Perl?
by jdporter (Paladin) on Mar 24, 2004 at 14:07 UTC

    No doubt some monks will be wondering about this "little known operator". My apologies to Abigail if he thinks I'm spoiling the fun.

    So let's break it down.

    First, we have a plain ol' here-doc, written as

    <<q This is a multiline comment. q
    Well and good. But, as Abigail points out, this can trigger a warning. The solution is to do something with the resulting string. In this case, we feed it to a regex binding operator: =~ q>>;

    This uses the single-q quoting operator to make an empty string. This results in a pretty useless regex, but at least we achieve our goal of doing something with the string created by the here-doc.

    So we have something which is equivalent to the following (approximately):

    "this is a comment" =~ //;
    In summary, there is no "little known << >> operator".

    Abigail++ for the neat trick!

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

Re: Answer: Better ways to make multi-line comments in Perl?
by Aristotle (Chancellor) on Mar 24, 2004 at 16:17 UTC
    See, there's something in Perl6 for everyone. :)

    Makeshifts last the longest.

Re: Answer: Better ways to make multi-line comments in Perl?
by Anonymous Monk on Aug 22, 2015 at 08:33 UTC
    the little known << >> operator.

    As of Perl 5.22, that statement might be a little confusing; from the 5.22.0 perldelta:

    New double-diamond operator

    <<>> is like <> but uses three-argument open to open each file in @ARGV. This means that each element of @ARGV will be treated as an actual file name, and "|foo" won't be treated as a pipe open.

      The <<>> operator doesn't take arguments. It only makes sense for the magical processing of STDIN and @ARGV files, not for an explicitly given file handle.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ