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

Re: Indented here docs?

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
July 1, 2016 16:20
Subject:
Re: Indented here docs?
Message ID:
20160701162041.GB25735@plasmasturm.org
* Matthew Horsfall (alh) <wolfsage@gmail.com> [2016-06-30 15:48]:
> 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").

I like everything about the proposal except (*groan*) the syntax. Yes,
sorry. But. I don’t need (and would be reluctant) to make up a counter
proposal myself. Because as it turns out, at least bash and zsh both
support this, and both of them use <<- for it.

So can we follow that precedent?

Unfortunately-ish, that already has a meaning in Perl: <<-EOF gets
parsed as `<< "" - EOF`, which is not a completely silly thing to do: if
the heredoc contains just one line with a number on it, Perl is happy to
ignore the trailing newline and do the subtraction without a warning.

Fortunately-ish, it throws a mandatory warning about the fact that using
bare << to imply <<"" is deprecated.

Frankly, I would be willing to turn that warning into an error and wait
out a release cycle if that will allow nicer syntax.

But maybe we can go just ahead already. I hope so, but I’m not confident
and would love to hear from anyone who can think of an obvious compat
issue I’m missing.

On grep.cpan.me there are 95 matches for <<- at the time of this writing
but of the half of them I’ve examined, most are comments or strings and
the rest are shell (scripts, or snippets passed to shell).

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | 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