Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Indented HEREDOC?

by LanX (Saint)
on Mar 20, 2018 at 17:51 UTC ( [id://1211359]=note: print w/replies, xml ) Need Help??


in reply to Indented HEREDOC?

Since this thread was my top-hit in google (YMMV):

Intended Here Documents were introduced with 5.26.

Indented Here-documents

This adds a new modifier "~" to here-docs that tells the parser that it should look for /^\s*$DELIM\n/ as the closing delimiter.

These syntaxes are all supported:

<<~EOF; <<~\EOF; <<~'EOF'; <<~"EOF"; <<~`EOF`; <<~ 'EOF'; <<~ "EOF"; <<~ `EOF`;

The "~" modifier will strip, from each line in the here-doc, the same whitespace that appears before the delimiter.

Newlines will be copied as-is, and lines that don't include the proper beginning whitespace will cause perl to croak.

For example:

if (1) { print <<~EOF; Hello there EOF }

prints "Hello there\n" with no leading whitespace.

Probably my favourite improvement since // defined-or.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1211359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found