Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRIM option creates output with no newline on the final line. [rt.cpan.org #60083] #97

Closed
atoomic opened this issue Oct 5, 2018 · 4 comments

Comments

@atoomic
Copy link
Collaborator

atoomic commented Oct 5, 2018

Migrated from rt.cpan.org#60083 (status was 'new')

Requestors:

Attachments:

From nick@leverton.org on 2010-08-04 19:31:21:

The TRIM option causes output files to be written without a newline on 
the final line, which upsets software that cares about such things.  
We are generating C/C++ code from templates and g++ complains - I 
understand a C++ source with incomplete final line can cause undefined 
behaviour according to the standards.

To reproduce, please see the attached program, which runs itself 
through Template::process, and check the output.

@toddr
Copy link
Collaborator

toddr commented Oct 5, 2018

test.pl:

#! /usr/bin/perl -w

use strict;

use Template;

# Create a template processor.
#
my $config = {'INCLUDE_PATH' => ".",
	      'OUTPUT_PATH'  => ".",
	      'TRIM'         => 1,
	      };
my $tt = Template->new($config)
  or die "Failed to create template processor: $Template::ERROR";

# Process the source template, to generate the output.
$tt->process($0,
	     { },
	     "$0.out")
  or die "Failed to process template foo: " . $tt->error();

@toddr
Copy link
Collaborator

toddr commented Oct 5, 2018

You could probably make use of an empty [% %] statement with prudent use of [% -%] to make the end line show up. I'd need to see your template though to be sure.

@toddr
Copy link
Collaborator

toddr commented Oct 5, 2018

you could also read in $0 and add a new line manually.

@toddr
Copy link
Collaborator

toddr commented Oct 9, 2018

I think the only answer I can give here is don't use TRIM. If you have a good reason that you need TRIM, let me know.

@toddr toddr closed this as completed Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants