develooper Front page | perl.perl5.porters | Postings from June 2016

Indented here docs?

Thread Next
June 30, 2016 13:42
Indented here docs?
Message ID:
Hello Porters.

Indented heredocs would be a wonderful feature to have, but I hear a
lot of people saying it's not possible.

I'm wondering why this is?

Attached is a *ROUGH* patch that adds new syntax to allow indented
heredocs, at least in this simple case:

  if (1) {
    print <<~EOF;
      Lorem Something Or Other

(It also allows <<~'EOF', <<~"EOF").

Right now, it doesn't remove the beginning indentation of the indented
heredoc, but it could easily, following Perl 6's rules perhaps:

  Lines with more indentation than the delimiter will appear indented
by however much extra space they use, and lines with less indentation
will be as indented as the delimiter, with a warning about the issue.

As I've implemented it, the closing delimiter must match:


So that $delim can exist anywhere in the text (excepting where it closes).

What am I missing? Can we do this?

Thanks for your time,

-- Matthew Horsfall (alh)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About