“Here” Documents
A line-oriented form of quoting is based on the Unix shell’s
here-document syntax.
It’s line-oriented in the sense that the delimiters are lines rather
than characters. The starting delimiter is the current line, and the
terminating delimiter is a line consisting of the string you
specify. Following a <<,
you specify the string to terminate the quoted material, and all
lines following the current line down to but not including the
terminating line are part of the string. The terminating string may
be either an identifier (a word) or some quoted text. If quoted, the
type of quote determines the treatment of the text, just as it does
in regular quoting. An unquoted identifier works as though it were
in double quotes. A backslashed identifier works as though it were
in single quotes (for compatibility with shell syntax). There must
be no space between the << and an
unquoted identifier, although whitespace is permitted if you specify
a quoted string instead of the bare identifier. (If you insert a
space, it will be treated as a null identifier, which is valid but
deprecated, and matches the first blank line—see the first Hurrah! example below.) The terminating
string must appear by itself, unquoted and with no extra whitespace
on either side, on the terminating line.
print <<EOF; # same as earlier example The price is $Price. EOF print <<"EOF"; # same as above, with explicit quotes The price is $Price. EOF print <<'EOF'; # single–quoted quote All things (e.g. a camel's ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access