quote heredocs :to

Documentation for quote heredocs :to, assembled from the following types:

language documentation Quoting Constructs

From Quoting Constructs

(Quoting Constructs) quote heredocs :to

A convenient way to write multi-line string literals are heredocs, which let you choose the delimiter yourself:

say q:to/END/; 
Here is
some multi-line
string
END

The contents of the heredoc always begin on the next line, so you can (and should) finish the line.

my $escaped = my-escaping-function(q:to/TERMINATOR/language => 'html'); 
Here are the contents of the heredoc.
Potentially multiple lines.
TERMINATOR

If the terminator is indented, that amount of indention is removed from the string literals. Therefore this heredoc

say q:to/END/; 
    Here is
    some multi line
        string
    END

produces this output:

Here is
some multi line
    string
 
 

Heredocs include the newline from before the terminator.

To allow interpolation of variables use the qq form, but you will then have to escape meta characters {\ as well as $ if it is not the sigil for a defined variable. For example:

my $f = 'db.7.3.8';
my $s = qq:to/END/; 
option \{
    file "$f";
};
END
say $s;

would produce:

option {
    file "db.7.3.8";
};

You can begin multiple Heredocs in the same line.

my ($first$second= qq:to/END1/qq:to/END2/; 
  FIRST
  MULTILINE
  STRING
  END1
   SECOND
   MULTILINE
   STRING
   END2