develooper Front page | perl.perl5.porters | Postings from October 2017

Re: [perl #128557] Trailing space in heredoc delimiter

Thread Previous
From:
Abigail
Date:
October 1, 2017 19:44
Subject:
Re: [perl #128557] Trailing space in heredoc delimiter
Message ID:
20171001191932.GA12919@almanda.fritz.box
On Sun, Oct 01, 2017 at 12:10:57PM -0700, Ed Avis via RT wrote:
> Thanks for your responses.  This bug report is based on real-world code; a lot of code (repeated SQL calls, or printing chunks of output) do have repeated heredoc uses, and if those all use the same delimiter (such as END) it is quite easy to silently include a trailing space -- not shown in most editors -- and end up with code that compiles but is wrong.
> 
> I filed the bug report because it's quite awkward that a space character (moreover, an end-of-line one, which are the most difficult to see) has such a large effect.  But forget the suggestion of adding a warning.  That gets bogged down in the usual back and forth about perlcritic (which I love, and run over the codebase regularly -- but not in every single edit-test cycle).  Could I ask instead whether the whitespace-sensitivity here is really needed?
> 
> What would happen if heredoc delimiters became like every other language token and weren't affected by space characters after them?  They will always be special because they do depend on start of line, but couldn't they be more relaxed about whitespace at the end?  Nothing else in the language is as fussy, and we know that with the mixture of different editors in use, trailing spaces tend to creep into code over time.  Wouldn't it be a sensible incremental improvement to allow whitespace after these heredoc terminators?
> 
> Note that the current behaviour is not exactly consistent: if you put the start of the heredoc as '<<END ' with a trailing space, it doesn't get terminated by the 'END ' you specified.  The trailing space on the starting heredoc delimiter is silently stripped.  Why not strip on the closing delimiter too?
> 


This does what you expect it to do:

    print << "END ";
    The line below does not end with a space:
    END
    The line below does end with a space:
    END


Abigail

Thread Previous


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