Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions pod/perlop.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2842,16 +2842,13 @@ must use an C<eval()>:
eval "tr/$oldlist/$newlist/, 1" or die $@;

=item C<< <<I<EOF> >>
X<here-doc> X<heredoc> X<here-document> X<<< << >>>
X<here-doc> X<here-docs> X<heredoc> X<here-document> X<<< << >>>

A line-oriented form of quoting is based on the shell "here-document"
syntax. Following a C<< << >> you specify a string to terminate
the quoted material, and all lines following the current line down to
the terminating string are the value of the item.

Prefixing the terminating string with a C<~> specifies that you
want to use L</Indented Here-docs> (see below).

The terminating string may be either an identifier (a word), or some
quoted text. An unquoted identifier works like double quotes.
There may not be a space between the C<< << >> and the identifier,
Expand All @@ -2862,6 +2859,52 @@ on the terminating line.
If the terminating string is quoted, the type of quotes used determine
the treatment of the text.

my $person = 'John';

print uc << "EOT";
Hello, $person!
And the text goes on.
EOT

This yields

HELLO, JOHN!
AND THE TEXT GOES ON.

The same result happens if the double quotes are omitted

my $person = 'John';
print uc <<EOT;
Hello, $person!
And the text goes on.
EOT

HELLO, JOHN!
AND THE TEXT GOES ON.

If instead, single quotes are used, we get

my $person = 'John';
print uc <<'EOT';
Hello, $person!
And the text goes on.
EOT

HELLO, $PERSON!
AND THE TEXT GOES ON.

You can do fancy things like call a function with the here-document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested phrasing: "like use the here-document as an argument to a function."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this is maybe out of place since the preceding examples already do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of grammatical pedantry here: s/like use/such as use/.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking further down in the pod, I realize it needs much more work


print uc(<<EOF);
abc
EOF

ABC

It is usually easier to read the code if the here-document is indented.
Prefixing the terminating string with a C<~> specifies that you
want to use L</Indented Here-docs> (see below).

=over 4

=item Double Quotes
Expand Down
Loading