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

Indented here docs?

Thread Next
From:
wolfsage
Date:
June 30, 2016 13:42
Subject:
Indented here docs?
Message ID:
CAJ0K8bjxkyQ-YpsFpQPYZ6QziGxDO9vs1eBQL38UkGEzg7jrJw@mail.gmail.com
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
    EOF
  }

(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:

  /^\s+$delim\n/

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About