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

Re: Indented here docs?

Thread Previous | Thread Next
From:
David Nicol
Date:
August 4, 2016 07:34
Subject:
Re: Indented here docs?
Message ID:
CAFwScO_C0c99TbRxMa8Q_jUEqJcwEa6QvkENU2WzybKMn-XvTA@mail.gmail.com
Furthermore, is the tilde supposed to be part of the chevron or part of the
delimiter? Without space allowed between them it appears to be a new
operator, making it part of the chevron, but by allowing space both before
and after, that introduces a new kind of token, the "heredoc modifier," of
which there is only currently one defined, which is tilde.

Having introduced this new kind of token, it then becomes possible to
declare ways to do the whole heredoc post-processing wishlist:

 << ~  EOF    the original, contents must be indented the same as line
where the expression the chevron appears in starts, under pain of error,
and that indentation is stripped

 << ~. EOF   chop the trailing newline

 << ~^ EOF   traditional heredoc semantics, allowing other modifiers
without discarding leading space

 << ~/^[ \t]*|#.*// EOF impose an arbitrary s///mg on the doc

 << ~^.{ MyFilter } EOF  the same as MyFilter(do { my $tmp = <<EOF; chop
$tmp; $tmp})

-- 
"It's like a whole other country."

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