Skip to content

Commit 3163338

Browse files
committed
Heredocs
1 parent 74326f7 commit 3163338

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lib/Language/quoting.pod

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,49 @@ execute external commands.
212212
213213
=head2 Heredocs: :to
214214
215-
TODO
215+
A convenient way to write multi-line string literals are I<heredocs>, which
216+
lets you chose the delimiter yourself:
217+
218+
=begin code
219+
say q:to/END/;
220+
Here is
221+
some multi line
222+
string
223+
END
224+
=end code
225+
226+
The contents of the heredoc only begin on the next line, so you can (and
227+
should finish the line).
228+
229+
=begin code
230+
my $escaped = escaque(q:to/TERMINATOR/, language => 'html');
231+
Here are the contents of the heredoc.
232+
Potentially multiple lines.
233+
TERMINATOR
234+
=end code
235+
236+
If the terminator is indented, that amount of indention is removed from the
237+
string literals.
238+
239+
=begin code
240+
say q:to/END/;
241+
Here is
242+
some multi line
243+
string
244+
END
245+
=end code
246+
247+
which produces
248+
249+
=begin code
250+
Here is
251+
some multi line
252+
string
253+
254+
255+
=end code
256+
257+
Heredocs include the newline from before the terminator.
216258
217259
=head1 Regexes
218260

0 commit comments

Comments
 (0)