Here document: Difference between revisions

 
(33 intermediate revisions by 20 users not shown)
Line 9:
;Task:
Demonstrate the use of   ''here documents''   within the language.
 
 
;Related task:
*   [[Documentation]]
<br><br>
 
{{omit from|Delphi}}
 
=={{header|11l}}==
11l does not have here-docs. It does however have raw strings which can be used similarly.
<langsyntaxhighlight lang="11l">print(‘
here
doc
’)</langsyntaxhighlight>
 
=={{header|8th}}==
Multiline strings are simply parsed using "quote", which parses first a character to use as a separator, and scans until that character is found:
<langsyntaxhighlight lang="forth">
quote *
Hi
there
* .
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 41 ⟶ 42:
A workaround is to use containers of strings:
 
<langsyntaxhighlight Adalang="ada">with Ada.Containers.Indefinite_Vectors, Ada.Text_IO;
 
procedure Here_Doc is
Line 60 ⟶ 61:
Ada.Text_IO.Put_Line(Document.Element(I));
end loop;
end Here_Doc;</langsyntaxhighlight>
 
{{out}}
Line 75 ⟶ 76:
It can be crudely achieved using an array of strings:
 
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
[]STRING help = (
Line 92 ⟶ 93:
"Dammit. Janet, I love you."
))
</syntaxhighlight>
</lang>
 
{{out}}
Line 106 ⟶ 107:
Dammit. Janet, I love you.</pre>
 
=={{header|APL}}==
{{works with|GNU APL}}
See the GNU APL docs: [https://www.gnu.org/software/apl/apl.html#Section-2_002e1 2.1.4 Helpful Features for Scripting]
<syntaxhighlight lang="apl">
BODY←⎕INP 'END-OF-⎕INP'
First line
Second line
Third line
...
END-OF-⎕INP
</syntaxhighlight>
A related concept is multi-line strings (note the 6 space indent of APL interactive input vs. output):
<syntaxhighlight lang="apl">
]boxing 8
s ← """
→ abc
→ def
→ GHIJK
→ """
s</syntaxhighlight>
{{out}}
<pre>┌┌→────────────────────────────────────────┐
│┌→──────┐ ┌→────────┐ ┌⊖┐ ┌→────────────┐ │
││ abc│ │ def│ │ │ │ GHIJK│ │
│└───────┘ └─────────┘ └─┘ └─────────────┘ │
└∊─────────────────────────────────────────┘</pre>
 
=={{header|Applesoft BASIC}}==
Strings are limited to 255 characters. The double quote character delimits strings, so double quote cannot be embedded directly. The double quote can be included in a DATA statement if the text is not wrapped in quotes. Most control characters, with the exception of Return ^M, Backspace ^H, Forward-space ^U and Escape ^[, can be typed into strings. Control characters are not usually visible. The line feed character ^J moves the cursor position down one line, and the ^G character is audible!
<syntaxhighlight lang="gwbasic"> 0 Q$ = CHR$ (34)
1 M$ = CHR$ (13)
2 PRINT Q$"Oh, Danny Boy,"M$"The pipes, the pipes are calling"M$"From glen to glen and down the mountainside"Q$</syntaxhighlight>
There are tools and tricks to embed control characters like Return directly into the program.
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program heredoc.s */
Line 165 ⟶ 200:
pop {r0,r1,r2,r7,lr} @ restaur registers
bx lr @ return
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">print {:
The “Red Death” had long devastated the country.
No pestilence had ever been so fatal, or so hideous.
 
Blood was its Avator and its seal—
the redness and the horror of blood.
 
There were sharp pains,
and sudden dizziness,
and then profuse bleeding at the pores,
with dissolution.
The scarlet stains upon the body
and especially upon the face of the victim,
were the pest ban
which shut him out from the aid
and from the sympathy of his fellow-men.
 
And the whole seizure,
progress and termination of the disease,
were the incidents of half an hour.
:}</syntaxhighlight>
 
{{out}}
 
<pre> The “Red Death” had long devastated the country.
No pestilence had ever been so fatal, or so hideous.
 
Blood was its Avator and its seal—
the redness and the horror of blood.
 
There were sharp pains,
and sudden dizziness,
and then profuse bleeding at the pores,
with dissolution.
The scarlet stains upon the body
and especially upon the face of the victim,
were the pest ban
which shut him out from the aid
and from the sympathy of his fellow-men.
 
And the whole seizure,
progress and termination of the disease,
were the incidents of half an hour.</pre>
 
=={{header|AutoHotkey}}==
AutoHotkey uses "continuation sections" for literal text:
 
<langsyntaxhighlight AutoHotkeylang="autohotkey">MyVar = "This is the text inside MyVar"
MyVariable =
(
Line 178 ⟶ 261:
Variable references such as %MyVar% are expanded.
)
MsgBox % MyVariable</langsyntaxhighlight>
 
=={{header|AWK}}==
 
The awk extraction and reporting language does not provide any markup facility for embedding here documents within an awk script. The awk utility is really a helper tool often used from within the Unix shell. The Unix shell in which awk scripts are usually embedded does support the use of here documents, and the way that here documents are used within the shell make them ideal for passing to awk as is, without the need for an additional facility in awk.
 
=={{header|BQN}}==
Works in: [[CBQN]]
 
The default string syntax in BQN allows multiline strings. Strings start and end with a double quote, and quotes within the text can be escaped by typing two quotes.
 
<syntaxhighlight lang="bqn">•Out "dsdfsdfsad
""fsadf""sdf"</syntaxhighlight><syntaxhighlight lang="text">dsdfsdfsad
"fsadf"sdf</syntaxhighlight>
 
=={{header|Bracmat}}==
Strings in Bracmat can continue over many lines. They start and end with a quote. Quotes in the text must be escaped with a reverse solidus, like the reverse solidus itself.
 
<langsyntaxhighlight lang="bracmat">( {Multiline string:}
"
Second line
Line 196 ⟶ 288:
& out$("Multiline string:")
& out$(!stringA)
)</langsyntaxhighlight>
Output:
<pre>Multiline string:
Line 207 ⟶ 299:
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="freebasic">
'--- we dont have a print here doc built-in command in BaCon
'--- sowe Ican madeget athe PRINTLINEend macroresult thatlike simulatesthis with the ideanewline NL$
DEF FN PRINTLINE(...) = fprintf(stdout, "%s\n", #__VA_ARGS__)
 
 
PRINTLINE(To use Bacon your system must have either Korn Shell, or ZShell, or Bourne Again Shell (BASH) available. \n If none of these shells are available on your platform, download and install the free Public Domain Korn Shell which can \n execute BaCon also. Furthermore BaCon also works with a newer Kornshell implementation like the MirBSD Korn Shell.\n \n BaCon intends to be a programming aid in creating tools which can be compiled on different platforms \n (including 64bit environments). It tries to revive the days of the good old BASIC. )
</lang>
 
PRINT "To use Bacon your system must have either Korn Shell, or ZShell, or Bourne Again Shell (BASH) available." NL$ \
"If none of these shells are available on your platform, download and install the free Public Domain Korn Shell which can" NL$ \
"execute BaCon also. Furthermore BaCon also works with a newer Kornshell implementation like the MirBSD Korn Shell." NL$ NL$ \
"BaCon intends to be a programming aid in creating tools which can be compiled on different platforms" NL$ \
"(including 64bit environments). It tries to revive the days of the good old BASIC." NL$
 
</syntaxhighlight>
Output:
<pre>To use Bacon your system must have either Korn Shell, or ZShell, or Bourne Again Shell (BASH) available.
Line 225 ⟶ 318:
(including 64bit environments). It tries to revive the days of the good old BASIC.</pre>
 
=={{header|C}}==
The program speaks for itself ;)
<lang C>
#include <stdio.h>
 
=={{header|BASIC}}==
int main() {
BASIC no tiene heredocs ni cadenas de varias líneas. Una solución
puts(
alternativa es unir varias cadenas en una línea con CHR$(10).
"The Heredoc task was marked not implementable in C.\n"
<syntaxhighlight lang="basic">
"Frankly the person who did so seems to have little idea\n"
text1$ = " " + CHR$(10) + "<<'FOO' " + CHR$(10) + " 'jaja', `esto`" + CHR$(10) + " <simula>" + CHR$(10) + " \un\" + CHR$(10) + " ${ejemplo} de 'heredoc'" + CHR$(10) + " en QBASIC."
"of what C is capable of.\n"
"After all, what would one call this multiline string?\n"
"I may be old, but do not forget that it all started with me.\n"
"Ever enigmatic...\n\n"
"C "
);
 
text2$ = "Esta es la primera línea." + CHR$(10) + "Esta es la segunda línea." + CHR$(10) + "Esta 'línea' contiene comillas."
return 0;
 
}
PRINT text1$
</lang>
PRINT
Output:
PRINT text2$
END
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
The Heredoc task was marked not implementable in C.
</pre>
Frankly the person who did so seems to have little idea
of what C is capable of.
After all, what would one call this multiline string?
I may be old, but do not forget that it all started with me.
Ever enigmatic...
 
 
C
=={{header|BASIC256}}==
BASIC256 no tiene heredocs ni cadenas de varias líneas. Una solución
alternativa es unir varias cadenas en una línea con chr(10).
<syntaxhighlight lang="basic256">
text1$ = " " & chr(10) & "<<#FOO# " & chr(10) & " #jaja#, `esto`" & chr(10) & " <simula>" & chr(10) & " \un\" & chr(10) & " ${ejemplo} de 'heredoc'" & chr(10) & " en BASIC256."
 
text2$ = "Esta es la primera linea." & chr(10) & "Esta es la segunda linea." & chr(10) & "Esta 'linea' contiene comillas."
 
print text1$
print
print text2$
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|Blade}}==
<syntaxhighlight lang="blade">echo 'All strings
support
multiline
in Blade'</syntaxhighlight>
{{out}}
<pre>
All strings
support
multiline
in Blade
</pre>
 
 
=={{header|C sharp}}==
C# has a string literal call which is used for heredoc functionality
 
<langsyntaxhighlight Clang="c sharp">using System;
 
class Program
Line 271 ⟶ 385:
in C#");
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
Line 277 ⟶ 391:
C++11 raw string literals are similar to heredocs, except there is no newline after the opening token or before the ending token (unless you actually want newlines there).
 
<langsyntaxhighlight lang="cpp">#include <iostream> // Only for cout to demonstrate
 
int main()
Line 294 ⟶ 408:
or recognized, and all whitespace is preserved.
)EOF";
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Line 304 ⟶ 418:
CoffeeScript borrows the triple-quoted string syntax from Python. Note that these strings strip leading whitespace in CoffeeScript, to allow you to neatly align the heredoc string.
 
<langsyntaxhighlight lang="coffeescript">myDoc = '''
Single-quoted heredocs allows no '#{foo}' interpolation.
This behavior is similar to single-quoted strings.
Line 314 ⟶ 428:
"""
 
console.log doc2</langsyntaxhighlight>
 
{{out}}
Line 330 ⟶ 444:
[https://github.com/e-user/cl-heredoc cl-heredoc] provide read-macro for heredoc:
 
<langsyntaxhighlight lang="lisp">;; load cl-heredoc with QuickLisp
(ql:quickload 'cl-heredoc)
 
Line 340 ⟶ 454:
no matter how many lines or what characters until
the magic end sequence has been reached!eof1)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 350 ⟶ 464:
 
Note: <code>NIL</code> is the return value of function <code>format</code> when first argument is <code>t</code>
 
=={{header|Crystal}}==
<syntaxhighlight lang="ruby">puts <<-DOC
this is a heredoc
it preserves indents and newlines
the DOC identifier is completely arbitrary
it can be lowercase, a keyword, or even a number (but not a float)
DOC</syntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio, std.string;
 
void main() {
Line 372 ⟶ 494:
 
// std.string.outdent is used to remove the four spaces indent.
}</langsyntaxhighlight>
{{out}}
<pre>a string that you "don't" have to escape
Line 382 ⟶ 504:
=={{header|DWScript}}==
Double-quotes (") denote a multi-line string, to include a double-quote in such a string, you need to double it.
<langsyntaxhighlight lang="delphi">PrintLn("This is
a multiline
""string""
sample");</langsyntaxhighlight>
{{out}}
<pre>This is
Line 391 ⟶ 513:
"string"
sample</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
# The here-document is not here, but at the end of the program
repeat
s$ = input
until error = 1
print s$
.
input_data
This is a 'raw' string with the following properties:
- indention is preserved,
- an escape sequence such as a quotation mark "\\" is interpreted literally, and
- interpolation such as %(a) is also interpreted literally.
- """ is also interpreted literally.
 
`Have fun!`
</syntaxhighlight>
{{out}}
<pre>
This is a 'raw' string with the following properties:
- indention is preserved,
- an escape sequence such as a quotation mark "\\" is interpreted literally, and
- interpolation such as %(a) is also interpreted literally.
- """ is also interpreted literally.
 
`Have fun!`
</pre>
 
=={{header|EchoLisp}}==
Line 444 ⟶ 594:
=={{header|Elixir}}==
In Elixir, one can use either a pair of triple single-quotation marks or a pair of triple double-quotation marks, but in both cases, string interpolation occurs:
<langsyntaxhighlight lang="elixir">IO.puts """
привет
мир
"""</langsyntaxhighlight>
produces:<langsyntaxhighlight lang="sh">привет
мир</langsyntaxhighlight>
 
Here is an illustrative iex transcript:
<langsyntaxhighlight lang="elixir">iex(1)> a=2
2
iex(2)> '''
Line 462 ⟶ 612:
** (SyntaxError) iex:3: heredoc start must be followed by a new line after '''
iex(3)></langsyntaxhighlight>
 
=={{header|Erlang}}==
Multiline strings look like this in the Erlang shell:
<syntaxhighlight lang="erlang">
<lang Erlang>
2> S = " ad
2> 123
Line 474 ⟶ 624:
123
the end
</syntaxhighlight>
</lang>
 
=={{header|F_Sharp|F#}}==
Line 490 ⟶ 640:
=={{header|Factor}}==
Factor strings surround by '"' are multiline, but accept escape sequences (like "\n", "\uxxxxxxxx"). Strings surrounded by '"""' don't have to escape '"'. Use HEREDOC: (and other variants, like <pre>[[</pre>) for verbatim text
<langsyntaxhighlight lang="factor">" a multiline
string\n(with escape sequences: \u{greek-capital-letter-sigma})
"
Line 500 ⟶ 650:
this
is not \n escaped at all
EOF</langsyntaxhighlight>
 
[[ this also works , but needs a space at the start (but not the end)]]
Line 513 ⟶ 663:
===version 1===
{{works with|GForth}}
<langsyntaxhighlight Forthlang="forth">\ GForth specific words:
\ under+ ( a b c -- a+c b) , latest ( -- nt ) , name>string ( nt -- ca u )
\ Should not be a problem to modify it to work with other Forth implementation:
Line 561 ⟶ 711:
>> RABBIT
RABBIT
ALICE type ." --" cr RABBIT type</langsyntaxhighlight>
 
<pre>
Line 579 ⟶ 729:
 
It's written to works with Forth's default implementation of counted strings. Those are limited to 255 characters, which is fine in many cases, but on the short side for here documents, so therefore we temporarily redefine them to use a full cell for size (16 bits would probably be ideal) while compiling the here document words.
<langsyntaxhighlight Forthlang="forth">get-current get-order wordlist swap 1+ set-order definitions
: place over >r rot over cell+ r> move ! ;
: +place 2dup >r >r dup @ cell+ + swap move r> r> dup @ rot + swap ! ;
Line 606 ⟶ 756:
~~ end ~~
 
Alice type bye</langsyntaxhighlight>
 
{{out}}
Line 619 ⟶ 769:
 
Producing a source file containing a block of text that will be presented as output in the same layout (new lines and all) is only possible if the added layout stuff (generating the required new line starts) and delimiters in the source are disregarded. But if one accepts a few constraints, the following shows a possible approach:
<syntaxhighlight lang="fortran">
<lang Fortran>
INTEGER I !A stepper.
CHARACTER*666 I AM !Sufficient space.
Line 637 ⟶ 787:
END DO !On to the next line.
END
</syntaxhighlight>
</lang>
With old-style fixed-format source, rather amusingly there is space for sixty-six characters of text per line and so this is the canvas. Any usage of tab characters must be resolved into spaces (and some compilers count up to 72 oddly when tabs are involved) and likewise with new lines. A surprise was provided to an old-time card flapper when it became apparent that trailing spaces were ''not'' being incorporated into the text literal unless the "<col72" markers were appended to column seventy-two of the source. An old-time card deck copied to disc and with the sequence numbers in columns 73-80 removed (as no-one is going to drop a disc file so some storage space can be saved) might thereby compile incorrectly! Similarly, the source text highlighter here does not fully recognise the odd tricks available for Fortran syntax, apparently deeming the comments a part of a text literal. The F90 compiler's highlighting does, and shows that text beyond column 72 is not Fortran code.
 
Line 654 ⟶ 804:
In Pascal, the only forbidden character in string literals is the newline character.
However, as of 2019‑09‑06 in a trunk version of the FPC (Free Pascal compiler) support for string literals spanning multiple lines can be enabled.
 
 
=={{header|FreeBASIC}}==
FreeBASIC no tiene heredocs ni cadenas de varias líneas. Una solución
alternativa es unir varias líneas con NL, LF, \n o Chr(10).
<syntaxhighlight lang="freebasic">
Dim As String text1 = " " & Chr(10) & _
"<<'FOO' " & Chr(10) & _
" 'jaja', `esto`" & Chr(10) & _
" <simula>" & Chr(10) & _
" \un\" & Chr(10) & _
!" ${ejemplo} de \"heredoc\"" & Chr(10) & _
" en FreeBASIC."
 
Dim As String text2 = "Esta es la primera linea." & Chr(10) & _
"Esta es la segunda linea." & Chr(10) & _
!"Esta \"linea\" contiene comillas."
 
Print text1
Print Chr(10) + text2
Sleep
</syntaxhighlight>
{{out}}
<pre>
<<'FOO'
'jaja', `esto`
<simula>
\un\
${ejemplo} de "heredoc"
en FreeBASIC.
 
Esta es la primera linea.
Esta es la segunda linea.
Esta "linea" contiene comillas.
</pre>
 
 
=={{header|Frink}}==
Frink does not have awkward here-docs. Triple-quoted strings serve the same purpose, but more concisely. (The Perl, PHP, etc. syntax for here-documents is a violation of the "define everything at most once" principle of software engineering.) Variable interpolation is allowed within triple-quoted strings.
<langsyntaxhighlight lang="frink">
lyrics = """Oh, Danny Boy,
The pipes, the pipes are calling
From glen to glen and down the mountainside"""
</syntaxhighlight>
</lang>
 
=={{header|Genie}}==
Genie includes triple quoted verbatim strings and "at" quoted template strings, which can be used as Heredoc data in source. Given the limitation of terminating quotes not being a user defined sequence, inner quotations will need to be escaped or transcluded.
 
<langsyntaxhighlight lang="genie">[indent=4]
/*
Here documents, as template and verbatim strings in Genie
Line 684 ⟶ 870:
 
stdout.printf("%s", multilineString)
stdout.printf("%s", templateString)</langsyntaxhighlight>
 
{{out}}
Line 698 ⟶ 884:
Go does not have here documents. Multiline string literals serve this purpose.
 
<langsyntaxhighlight lang="go">var m = ` leading spaces
 
and blank lines`</langsyntaxhighlight>
 
=={{header|Groovy}}==
Line 707 ⟶ 893:
===Multi-line String literal===
The literal text, preserving lines and spacing
<langsyntaxhighlight lang="groovy">println '''
Time's a strange fellow;
more he gives than takes
Line 714 ⟶ 900:
losing, gaining
--love! if a world ends
'''</langsyntaxhighlight>
 
{{out}}
Line 728 ⟶ 914:
===Multi-line GString expression===
Like single-line GString expressions, any subexpression delimited with ${ } is substituted with its "toString()" value. Preserves lines and spacing outside of the subexpressions.
<langsyntaxhighlight lang="groovy">def expired='defunct'
def horse='stallion'
def christ='Jesus'
Line 745 ⟶ 931:
how do you like your blueeyed boy
Mister Death
"""</langsyntaxhighlight>
 
{{out}}
Line 767 ⟶ 953:
You could use [https://hackage.haskell.org/package/raw-strings-qq raw-strings-qq], or alternatively:
 
<syntaxhighlight lang="haskell">
<lang Haskell>
 
main :: IO ()
Line 786 ⟶ 972:
]
 
</syntaxhighlight>
</lang>
 
Output:
Line 803 ⟶ 989:
 
=={{header|J}}==
<langsyntaxhighlight lang="j">here=:0 :0
0 :0 will be replaced by the text on the following lines.
This is three tokens: two instances of the number 0 and
Line 842 ⟶ 1,028:
note that this mechanism is significantly more verbose than using
the underlying 0 :0 mechanism directly.
)
)</lang>
 
also_here=: {{)n
J902 introduced {{ blocks which may be {{ nested }} arbitrarily }} to
the J interpreter. This includes {{)n blocks which are here documents.
These {{)n blocks are not further nestable (they represent
literal text with no internal structure), and the terminating }}
must appear at the beginning of a line (or on the same line as
the opening {{)n -- but that would not be a "here doc").
 
If text does not appear after the )n on the initial line, the
initial (first) linefeed does not appear in the here doc. If
text follows the {{)n, that text (and optional newline) would
be included.
}}</syntaxhighlight>
 
=={{Header|Java}}==
[[User:Sjharper79|Sjharper79]] ([[User talk:Sjharper79|talk]])
 
====Compatibility====
The Java feature 'Text Blocks' is only available with JDK 15 and above.
 
====Syntax====
You must include a newline character after the opening """, you cannot include any Strings after the opening """. The closing """ does not have to be on its own line.
 
See [https://www.demo2s.com/java/java-17-string-block-for-multiline-java-string.html Java 17 String block for Multiline Java String].
 
<syntaxhighlight lang=java>
package rosettacode.heredoc;
public class MainApp {
public static void main(String[] args) {
String hereDoc = """
This is a multiline string.
It includes all of this text,
but on separate lines in the code.
""";
System.out.println(hereDoc);
}
}
</syntaxhighlight>
 
====Output====
<pre>
This is a multiline string.
It includes all of this text,
but on separate lines in the code.
</pre>
 
=={{header|JavaScript}}==
Line 848 ⟶ 1,080:
ES6 introduced template literals. These are string literals that suport multi-line text and can include
interpolated expressions using ${···} syntax. It is indicated with the backtich character [`]
<langsyntaxhighlight JavaScriptlang="javascript">const myVar = 123;
const tempLit = `Here is some
multi-line string. And here is
Line 854 ⟶ 1,086:
That's all.`;
console.log(tempLit)
</syntaxhighlight>
</lang>
 
<pre>Here is some
Line 864 ⟶ 1,096:
No special syntax is required to support "here documents" in jq in that any JSON string, and indeed any string specifier (as explained below), can be presented using a multiline format.
 
For example, consider:<langsyntaxhighlight lang="jq">
def s:
"x
Line 870 ⟶ 1,102:
z";
 
s</langsyntaxhighlight>
{{Out}}
<langsyntaxhighlight lang="sh">$ jq -n s.jq
"x\ny\nz"</langsyntaxhighlight>
 
String specifiers, that is possibly non-JSON strings which incorporate references to jq expressions, are handled in the same way. For example, the following program produces the same result:
<langsyntaxhighlight lang="jq">def specifier(a):
"x
\(a)
z";
 
specifier("y")</langsyntaxhighlight>
 
Most control characters, such as Control-A and Control-Z, can also be presented literally, but the RosettaCode.org editor disallows them in general, so the next example only shows an embedded literal tab:
<langsyntaxhighlight lang="jq">"a
tab: end
parens:()
Line 890 ⟶ 1,122:
double quotation mark must be escaped:\"
b
d"</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">"a\ntab:\tend\nparens:()\nsingle quotation mark:'\ndouble quotation mark must be escaped:\"\nb\nd"</langsyntaxhighlight>
 
=={{header|Julia}}==
Like Python, Julia has triple-quoted string literals, which are similar to here-docs:
 
<langsyntaxhighlight lang="julia">print("""\
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
""")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
Line 911 ⟶ 1,143:
 
Here's an example of all this:
<langsyntaxhighlight lang="scala">// version 1.1.0
 
fun main(args: Array<String>) {
Line 938 ⟶ 1,170:
 
println(here)
}</langsyntaxhighlight>
 
{{out}}
Line 966 ⟶ 1,198:
Lambdatalk inverts the standard evaluation process, nothing is evaluated out of S-expressions {first rest}.
 
<langsyntaxhighlight lang="scheme">
1) defining a variable:
{def myVar 123}
Line 982 ⟶ 1,214:
the value of "myVar": 123
That's all.
</syntaxhighlight>
</lang>
 
=={{header|langur}}==
Use a block modifier on a string literal using the qs or QS form to generate a blockquote. The block modifier must be the last modifier.
{{works with|langur|0.6}}
 
<syntaxhighlight lang="langur">val .s = qs:block END
Use a block modifier on a string literal using the q or Q form to generate a blockquote. The block modifier must be the last modifier.
We put our text here.
Here we are, Doc.
END</syntaxhighlight>
 
Use the lead modifier to strip leading white space on each line.
 
<langsyntaxhighlight lang="langur">val .s = qqs:lead:block END
We put our text here.
Here we are, Doc.
END</langsyntaxhighlight>
 
We can also use this with a regex literal. Note that this does not make the regex pattern "free-spacing." Use the x modifier for that.
 
<langsyntaxhighlight lang="langur">val .re = re:block END
a regex pattern here
Still here, Doc.
END</langsyntaxhighlight>
 
<langsyntaxhighlight lang="langur">val .re = re:x:block END
a free-spacing regex pattern here
Somewhere, Doc.
END</langsyntaxhighlight>
 
=={{header|Lingo}}==
Line 1,010 ⟶ 1,247:
But you can define multi-line strings using the line continuation character "\":
 
<langsyntaxhighlight lang="lingo">str = "This is the first line.\
This is the second line.\
This "&QUOTE&"line"&QUOTE&" contains quotes."
 
put str</langsyntaxhighlight>
{{out}}
<pre>
Line 1,022 ⟶ 1,259:
</pre>
 
For longer text it's more comfortable to put it into a named "field member" (=asset container) and load its text into a variable when needed:<langsyntaxhighlight lang="lingo">str = member("my long text").text
put str</langsyntaxhighlight>
 
=={{header|Lua}}==
Lua uses the [ [ to mark the start of a dochere block and ] ] to mark the end. It can be used directly or while assigning strings to a variable. An arbitrary but matching number of = may be placed between the brackets in both delimiters to allow ] ] to appear in the string.
<langsyntaxhighlight lang="lua">
print([[
This is a long paragraph of text
Line 1,045 ⟶ 1,282:
print(msg)
 
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
A block of { } can be used for code and for text. Editor in M2000 environment can color code/string on the fly, analyzing the first line, where the block start.
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
a$={This is the first line
Line 1,058 ⟶ 1,295:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Print["Mathematica
is an
interesing
Line 1,073 ⟶ 1,310:
when not
back\
s\\ashed!"];</langsyntaxhighlight>
{{out}}
<pre>Mathematica
Line 1,086 ⟶ 1,323:
when not
backs\ashed!</pre>
 
=={{header|MATLAB}}==
Matlab has no built-in heredoc syntax. The closest thing you can do is the following:
<syntaxhighlight lang="matlab">sprintf('%s\n',...
'line1 text',...
' line2 text',...
' line3 text',...
' line4 text')
 
sprintf('%s\n',...
'Usage: thingy [OPTIONS]',...
' -h Display this usage message',...
' -H hostname Hostname to connect to')</syntaxhighlight>
{{out}}
<pre>
'line1 text
line2 text
line3 text
line4 text
'
 
'Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
'</pre>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">; here-document.lsp
; oofoe 2012-01-19
; http://rosettacode.org/wiki/Here_document
Line 1,098 ⟶ 1,360:
[/text] "James" "magician" "doctor" "L. McCoy"))
 
(exit)</langsyntaxhighlight>
 
{{out}}
Line 1,110 ⟶ 1,372:
 
There are no heredocs, but triple-quoted-strings can be used:
<langsyntaxhighlight lang="nim">echo """Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
"""</langsyntaxhighlight>
 
=={{header|NMAKE.EXE}}==
<langsyntaxhighlight lang="nmake.exe">target0: dependent0
command0 <<
temporary, discarded inline file
Line 1,138 ⟶ 1,400:
named and preserved inline file
...
<<KEEP</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">
print_string {whatever|
'hahah', `this`
Line 1,151 ⟶ 1,413:
|whatever}
;;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,178 ⟶ 1,440:
In Perl, there must not be a space between the "<<" and the token string. By default, the ending token must the entire end line (i.e. no surrounding spaces) for it to be recognized (but see exception below). Interpolation is allowed, like a double-quoted string:
 
<langsyntaxhighlight lang="perl">$address = <<END;
1, High Street,
$town_name,
West Midlands.
WM4 5HD.
END</langsyntaxhighlight>
 
If the token string contains spaces, the token after the "<<" must be quoted; otherwise the double-quotes is implicit:
<langsyntaxhighlight lang="perl">$pancake = <<"NO MORE INGREDIENTS";
egg
milk
flour
NO MORE INGREDIENTS</langsyntaxhighlight>
 
It is possible to make a here-document that behaves differently than a double-quoted string, by applying a different kind of quoting to the token. For example, if you use single quotes, then the here document will not support interpolation, like a normal single-quoted string:
 
<langsyntaxhighlight lang="perl">$x = <<'FOO';
No
$interpolation
here
FOO</langsyntaxhighlight>
 
Alternately, you can use backticks to cause the here document to be executed
and the result returned, just like a normal backtick operator:
 
<langsyntaxhighlight lang="perl">$output = <<`BAR`;
ls /home
BAR</langsyntaxhighlight>
 
Note that in the above examples, that a semicolon was left
Line 1,217 ⟶ 1,479:
nested expression:
 
<langsyntaxhighlight lang="perl">print(<<EOF . "lamb\n");
Mary had
a little
EOF</langsyntaxhighlight>
 
Since Perl 5.26, the here document can be indented by putting a '~' before the token. All spaces to the left of the ending token then become insignificant. This avoids having a disconcerting exdent in the middle of your code.
 
<langsyntaxhighlight lang="perl">sub flibbertigibbet {
print <<~END;
Mary had
Line 1,230 ⟶ 1,492:
lamb
END
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Phix does not have here-docs. In Phix normal double quoted strings are single line and require escaping. Strings can also be entered by using triple doublequotes or single backticks to include linebreaks and avoid any backslash interpretation. If the literal begins with a newline, it is discarded and any immediately following leading underscores specify a (maximum) trimming that should be applied to all subsequent lines. Interpolation is left to printf and friends. Both """`""" and `"""` are valid. Examples:
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>string ts1 = """
<span style="color: #004080;">string</span> <span style="color: #000000;">ts1</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
this
this
"string"\thing"""
"string"\thing"""</span>
 
string ts2 = """this
<span style="color: #004080;">string</span> <span style="color: #000000;">ts2</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""this
"string"\thing"""
"string"\thing"""</span>
 
string ts3 = """
<span style="color: #004080;">string</span> <span style="color: #000000;">ts3</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
_____________this
_____________this
"string"\thing"""
"string"\thing"""</span>
 
string ts4 = `
<span style="color: #004080;">string</span> <span style="color: #000000;">ts4</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
this
this
"string"\thing`
"string"\thing`</span>
 
string ts5 = `this
<span style="color: #004080;">string</span> <span style="color: #000000;">ts5</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`this
"string"\thing`
"string"\thing`</span>
 
string ts6 = `
<span style="color: #004080;">string</span> <span style="color: #000000;">ts6</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`
_____________this
_____________this
"string"\thing`
"string"\thing`</span>
 
string ts7 = "this\n\"string\"\\thing"
<span style="color: #004080;">string</span> <span style="color: #000000;">ts7</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"this\n\"string\"\\thing"</span>
 
constant tests={ts1,ts2,ts3,ts4,ts5,ts6,ts7}
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">={</span><span style="color: #000000;">ts1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ts7</span><span style="color: #0000FF;">}</span>
for i=1 to length(tests) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
for j=1 to length(tests) do
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
if tests[i]!=tests[j] then crash("error") end if
<span style="color: #008080;">if</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"error"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
printf(1,"""
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"""
____________Everything
____________Everything
(all %d tests)
works (all %d tests)
justworks
file.""",length(tests)) just
file."""</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">))</span>
printf(1,"""`""")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"""`"""</span><span style="color: #0000FF;">)</span>
printf(1,`"""`)</lang>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"""`</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,289 ⟶ 1,553:
Interpolation is allowed, like a double-quoted string:
 
<langsyntaxhighlight lang="php">$address = <<<END
1, High Street,
$town_name,
West Midlands.
WM4 5HD.
END;</langsyntaxhighlight>
 
In PHP 5.3+, it is possible to make a here-document that does not interpolate
Line 1,300 ⟶ 1,564:
(like in Perl):
 
<langsyntaxhighlight lang="php">$x = <<<'FOO'
No
$interpolation
here
FOO;</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
We can use the '[http://software-lab.de/doc/refH.html#here here]' function:
 
<langsyntaxhighlight PicoLisplang="picolisp">(out "file.txt" # Write to "file.txt"
(prinl "### This is before the text ###")
(here "TEXT-END")
Line 1,317 ⟶ 1,581:
TEXT-END
 
(in "file.txt" (echo)) # Show "file.txt"</langsyntaxhighlight>
 
{{out}}
Line 1,332 ⟶ 1,596:
The Key is the At symbol @.
 
<syntaxhighlight lang="powershell">
<lang PowerShell>
$XMLdata=@"
<?xml version="1.0" encoding="utf-8"?>
Line 1,350 ⟶ 1,614:
</unattend>
"@
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
Line 1,356 ⟶ 1,620:
It does however have [http://docs.python.org/py3k/tutorial/introduction.html#strings triple-quoted strings] which can be used similarly.
 
<langsyntaxhighlight lang="python">print("""\
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
""")</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 1,367 ⟶ 1,631:
that this implies (breaks code indentation, no "interpolation"):
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket/base
 
Line 1,376 ⟶ 1,640:
EOF
)
</syntaxhighlight>
</lang>
{{out}}
<pre> Blah blah blah
Line 1,385 ⟶ 1,649:
that works well with code:
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang at-exp racket/base
 
Line 1,406 ⟶ 1,670:
(output @list|<<{And customizable delimiters
so @foo{} is just plain text}>>|)
</syntaxhighlight>
</lang>
{{out}}
<pre>Blah blah blah
Line 1,424 ⟶ 1,688:
The indentation of the end marker is removed from every line.
 
<syntaxhighlight lang="raku" perl6line>my $color = 'green';
say qq :to 'END';
some line
color: $color
another line
END</langsyntaxhighlight>
{{out}}
<pre>some line
Line 1,440 ⟶ 1,704:
Multiple here docs may be stacked on top of each other.
 
<syntaxhighlight lang="raku" perl6line>my $contrived_example = 'Dylan';
sub freewheelin() {
print q :to 'QUOTE', '-- ', qq :to 'AUTHOR';
Line 1,450 ⟶ 1,714:
}
 
freewheelin;</langsyntaxhighlight>
 
{{out}}
Line 1,461 ⟶ 1,725:
Both q and qq are specialised forms of [http://design.raku.org/S02.html#Q_forms Q] which comes with many adverbs. Here a heredoc that only interpolates @-sigils.
 
<syntaxhighlight lang="raku" perl6line>my @a = <1 2 3 4>;
say Q :array :to 'EOH';
123 \n '"`
@a$bc
@a[]
EOH</langsyntaxhighlight>
 
{{out}}
Line 1,476 ⟶ 1,740:
=={{header|Raven}}==
As a list:
<langsyntaxhighlight Ravenlang="raven">'Buffy the Vampire Slayer' as sender
'Spike' as recipient
 
Line 1,487 ⟶ 1,751:
"%(sender)s
] "\n" join print
</syntaxhighlight>
</lang>
Using group to place the data on the stack:
<langsyntaxhighlight Ravenlang="raven">'Buffy the Vampire Slayer' as sender
'Spike' as recipient
 
Line 1,500 ⟶ 1,764:
%(sender)s\n"
list "\n" join print
</syntaxhighlight>
</lang>
{{out}}
<pre>Dear Spike,
Line 1,510 ⟶ 1,774:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program demonstrates a method to use "here" documents in REXX. */
parse arg doc . /*"here" name is case sensitive. */
 
Line 1,570 ⟶ 1,834:
└─────────┘
◄◄.
────────────────────────────────────end of "here" docs──────────────────*/</langsyntaxhighlight>
{{out}} when using the input of: <tt> rs-232 </tt>
<pre>
Line 1,621 ⟶ 1,885:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
text ="
<<'FOO'
Line 1,633 ⟶ 1,897:
to come to the aid of their country."
see text + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,652 ⟶ 1,916:
Interpolation is allowed, like a double-quoted string:
 
<langsyntaxhighlight lang="ruby">address = <<END
1, High Street,
#{town_name},
West Midlands.
WM4 5HD.
END</langsyntaxhighlight>
 
If the token string contains spaces, the token after the "<<" must be quoted; otherwise the double-quotes is implicit:
 
<langsyntaxhighlight lang="ruby">pancake = <<"NO MORE INGREDIENTS"
egg
milk
flour
NO MORE INGREDIENTS</langsyntaxhighlight>
 
It is possible to make a here-document that behaves differently than a double-quoted string, by applying a different kind of quoting to the token.
For example, if you use single quotes, then the here document will not support interpolation, like a normal single-quoted string:
 
<langsyntaxhighlight lang="ruby">x = <<'FOO'
No
#{interpolation}
here
FOO</langsyntaxhighlight>
 
Alternately, you can use backticks to cause the here document to be executed
and the result returned, just like a normal backtick operator:
 
<langsyntaxhighlight lang="ruby">output = <<`BAR`
ls /home
BAR</langsyntaxhighlight>
 
The here document does not start immediately at the "<<END" token -- it starts on the next line.
Line 1,688 ⟶ 1,952:
To further illustrate this fact, we can use the "<<END" inside a complex, nested expression:
 
<langsyntaxhighlight lang="ruby">puts <<EOF + "lamb"
Mary had
a little
EOF</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">text$ ="
<<'FOO'
Now
Line 1,704 ⟶ 1,968:
good mem
to come to the aid of their country."
print text$</langsyntaxhighlight>
{{out}}
<pre><<'FOO'
Line 1,720 ⟶ 1,984:
Similar to [[#C++|C++]], Rust offers raw strings. In a manner resembling [[#Lua|Lua]]'s delimiters, an arbitrary but matching number of # on both ends may be used to allow inclusion of # into the string:
 
<langsyntaxhighlight lang="rust">let x = r#"
This is a "raw string literal," roughly equivalent to a heredoc.
"#;
Line 1,727 ⟶ 1,991:
This string contains a #.
"##;
</syntaxhighlight>
</lang>
 
=={{header|Scala}}==
Line 1,735 ⟶ 1,999:
Triple quotes (""") marks the beginning and end.
Specially handy when using escape sequences in e.g. regular expressions.
{{libheader|Scala}}<langsyntaxhighlight Scalalang="scala">object temp {
val MemoriesOfHolland=
"""Thinking of Holland
Line 1,761 ⟶ 2,025:
|with its lapping disasters
|is feared and hearkened.""".stripMargin
}</langsyntaxhighlight>
All control codes are transparent e.g. new lines.
In order for a neat code each lines has as prefix spaces and a | symbol
which will be removed by the stripMargin function.
 
=={{header|sed}}==
<syntaxhighlight lang="sed">c\
The commands 'a', 'c', and 'i' can be followed\
by multi-line text. Each line break in the text\
is preceded by a backslash.</syntaxhighlight>
{{out}}
<pre>
$ echo | sed -f heredoc.sed
The commands 'a', 'c', and 'i' can be followed
by multi-line text. Each line break in the text
is preceded by a backslash.
</pre>
 
=={{header|SenseTalk}}==
SenseTalk has "block quotes" for large blocks of text, enclosed between <nowiki>"{{"</nowiki> (at the end of a line) and "}}" (at the beginning of a line). A tag can also be used after the <nowiki>"{{"</nowiki> and before the "}}" which allows for nesting of blocks, such as for a block of code containing other block quotes.
 
<langsyntaxhighlight lang="sensetalk">
set script to {{SCRIPT
put "Script demonstrating block quotes"
Line 1,784 ⟶ 2,061:
do script
 
</syntaxhighlight>
</lang>
 
=={{header|SequenceL}}==
<langsyntaxhighlight lang="sequencel">main :=
"In SequenceL
strings are
Line 1,795 ⟶ 2,072:
characters are
valid for inclusion
in a string.";</langsyntaxhighlight>
 
{{out}}
Line 1,813 ⟶ 2,090:
When the token string is double-quoted ("") or not quoted,
the content will be interpolated like a double-quoted string:
<langsyntaxhighlight lang="ruby">var text = <<"EOF";
a = #{1+2}
b = #{3+4}
EOF</langsyntaxhighlight>
 
If single quotes are used, then the here document will not support interpolation, like a normal single-quoted string:
<langsyntaxhighlight lang="ruby">var x = <<'FOO';
No
#{interpolation}
here
FOO</langsyntaxhighlight>
The here document does not start immediately at the "<<END" token -- it starts on the next line. The "<<END" is actually an expression, whose value will be substituted by the contents of the here document.
To further illustrate this fact, we can use the "<<END" inside a complex, nested expression:
<langsyntaxhighlight lang="ruby">say (<<EOF + "lamb");
Mary had
a little
EOF</langsyntaxhighlight>
which is equivalent with:
<langsyntaxhighlight lang="ruby">say (<<EOF
Mary had
a little
EOF
+ "lamb");</langsyntaxhighlight>
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
With SQL only from command line. The single quote string is opened along the three lines:
<langsyntaxhighlight lang="bash">
db2 "select 'This is the first line.
This is the second line.
This is the third line.' from sysibm.sysdummy1"
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,856 ⟶ 2,133:
</pre>
With SQL only from script with concat function (one row):
<langsyntaxhighlight lang="sql pl">
select 'This is the first line.' || chr(10) ||
'This is the second line.' || chr(10) ||
'This is the third line.' from sysibm.sysdummy1;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,872 ⟶ 2,149:
</pre>
With SQL only from script with union operator (three rows):
<langsyntaxhighlight lang="sql pl">
select 'This is the first line.' from sysibm.sysdummy1
union
Line 1,878 ⟶ 2,155:
union
select 'This is the third line.' from sysibm.sysdummy1;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,891 ⟶ 2,168:
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<langsyntaxhighlight lang="sql pl">
SET serveroutput ON
CALL DBMS_OUTPUT.PUT_LINE('This is the first line.' || chr(10) ||
'This is the second line.' || chr(10) ||
'This is the third line.');
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,908 ⟶ 2,185:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">set hereDocExample {
In Tcl, the {curly brace} notation is strictly a here-document style notation
as it permits arbitrary content inside it *except* for an unbalanced brace.
Line 1,920 ⟶ 2,197:
plus all whitespace at the start of the next line
to be compressed to a single space.
}</langsyntaxhighlight>
 
If substitution is desired within the document, it should either be written
Line 1,940 ⟶ 2,217:
to the resulting script which are interpreted by txr.
 
<langsyntaxhighlight lang="txr">#!/usr/bin/txr -f
@(maybe)
@(bind USER "Unknown User")
Line 1,952 ⟶ 2,229:
 
The Computer
@(end)</langsyntaxhighlight>
 
Test runs
Line 1,993 ⟶ 2,270:
{{works with|Bourne Shell}}
 
<langsyntaxhighlight lang="bash">#!/bin/sh
cat << ANARBITRARYTOKEN
The river was deep but I swam it, Janet.
Line 2,000 ⟶ 2,277:
I've one thing to say and that's ...
Dammit. Janet, I love you.
ANARBITRARYTOKEN</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">cat << EOF
Here documents do parameter and command substitution:
* Your HOME is $HOME
* 2 + 2 is `expr 2 + 2`
* Backslash quotes a literal \$, \` or \\
EOF</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">if true; then
cat <<- EOF
The <<- variant deletes any tabs from start of each line.
EOF
fi</langsyntaxhighlight>
 
<langsyntaxhighlight lang="bash">cat << 'TOKEN'
If TOKEN has any quoted characters (like 'TOKEN', "TOKEN" or \TOKEN),
then all $ ` \ in the here document are literal characters.
 
$PATH \$PATH `shutdown now`
TOKEN</langsyntaxhighlight>
<langsyntaxhighlight lang="bash">echo '
In any unix shell, you specify a text block and can use all whitespace like
(spaces) & (tab) in it, by using single quotes.
Line 2,029 ⟶ 2,306:
conform to the task definition.
'
</syntaxhighlight>
</lang>
 
==={{header|C Shell}}===
<langsyntaxhighlight lang="csh">#!/bin/csh -f
cat << ANARBITRARYTOKEN
* Your HOME is $HOME
Line 2,040 ⟶ 2,317:
cat << 'ANARBITRARYTOKEN'
$PATH \$PATH `shutdown now`
'ANARBITRARYTOKEN'</langsyntaxhighlight>
 
=={{header|Ursala}}==
<langsyntaxhighlight Ursalalang="ursala">hd =
 
-[
Line 2,092 ⟶ 2,369:
the periods like this -[.. ~&]-. This one is a second order function
that needs to be applied to another function in order to get a
first order function such as the previous three examples.]-</langsyntaxhighlight>
 
=={{header|VBScript}}==
Line 2,099 ⟶ 2,376:
 
It will prompt you to select a Txt-based file and do its best to create VBScript code that will recreate that Txt-based file!
<syntaxhighlight lang="vbscript">
<lang VBScript>
'Purpose: Converts TXT files into VBS code with a function that returns a text string with the contents of the TXT file
' The TXT file can even be another VBS file.
Line 2,183 ⟶ 2,460:
 
WshShell.Popup "created " & strFileNameOUT, 3, "Completed", 64
</syntaxhighlight>
</lang>
 
=={{header|V (Vlang)}}==
Vlang does not have here documents. Multiline string literals serve this purpose.
 
<syntaxhighlight lang="go">fn main() {
m := ' leading spaces
and blank lines'
 
println(m)
}</syntaxhighlight>
 
=={{header|Wren}}==
Wren hasdoes neithernot have heredocs norbut (from v0.4.0) does have raw strings.
 
A raw string is any text delimited by triple quotes, """, and is interpreted literally i.e. any control codes and/or interpolations are not processed as such.
Embedding escape characters in ordinary strings is not too bad in practice as the language doesn't use single quotes or back-ticks at all so these don't need to be escaped. A reasonable workaround is therefore to use a list of strings (one per line) and then join them together with the '\n' newline character.
 
If a triple quote appears on its own line then any trailing whitespace on that line is ignored.
However, if there's a lot of text, it's probably best to just load it in from a file.
 
Borrowing the Ada example (appropriately adjusted) for an illustration of thea formerraw approach:string.
<langsyntaxhighlight ecmascriptlang="wren">var a = [42
var b = """
"This is a list of 'strings' with the following properties:",
This is a 'raw' string with the following properties:
" - indention is preserved, and",
- indention is preserved,
" - a quotation mark '\"' must be \"escaped\" by preceding it with a '\\'.",
- an escape sequence such as a quotation mark "\\" is interpreted literally, and
"`Have fun!`"
- interpolation such as %(a) is also interpreted literally.
]
`Have fun!`
System.print(a.join("\n"))</lang>
"""
System.print(b)</syntaxhighlight>
 
{{out}}
<pre>
This is a list of 'stringsraw' string with the following properties:
- indention is preserved, and
- an escape sequence such as a quotation mark '"' must be "escaped\\" byis precedinginterpreted itliterally, with a '\'.and
- interpolation such as %(b) is also interpreted literally.
`Have fun!`
</pre>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code Text=12;
Text(0, " ^"Heredocs^" are pretty much automatic. Multiple lines and
whitespace, such as indentations, are output exactly as written. Quote
marks (^") and any carets (^^) within the string must be escaped.")</langsyntaxhighlight>
 
=={{header|XSLT}}==
Line 2,219 ⟶ 2,510:
Being a dialect of XML, XSLT inherits [http://www.w3.org/TR/REC-xml/#sec-cdata-sect CDATA sections]. Not quite heredocs, these are more like raw triple quotes in Python (<code>r"""…"""</code>) or Scala (<code>"""…"""</code>) in that anything except the end delimiter is treated literally.
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
Line 2,243 ⟶ 2,534:
]]>
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
 
Output from xsltproc (input is ignored):
Line 2,268 ⟶ 2,559:
 
</pre>
 
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">
text1$ = "Esta es la primera linea.
Esta es la segunda linea.
Esta \"linea\" contiene comillas.\n"
 
text2$ = "Blast it James! I'm a magician,
not a doctor!
--- L. McCoy\n"
 
 
print text1$
print text2$
end
</syntaxhighlight>
{{out}}
<pre>
Esta es la primera linea.
Esta es la segunda linea.
Esta "linea" contiene comillas.
 
Blast it James! I'm a magician,
not a doctor!
--- L. McCoy
</pre>
 
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">x:=
#<<<
"#<<< starts a block of lines that are concatenated verbatim
Line 2,278 ⟶ 2,597:
Note that is isn't a string, but arbitrary source " + 1 + 23;
#<<<
x.println();</langsyntaxhighlight>
{{out}}
<pre>
Line 2,292 ⟶ 2,611:
{{omit from|BASIC}}
{{omit from|BBC BASIC}}
{{omit from|C|C's "multi-line strings" don't fulfill the requirements of this task}}
{{omit from|Déjà Vu}}
{{omit from|Gambas}}
885

edits