0

I am running into a strange issue with Template toolkit for Perl. I have been using it to generate some Readme files using templates that is encoded in utf8, earlier this year, the readme file that was generated was fine and was in Dos\Windows style of utf8 encoding, with CR\LF as line endings. Somehow something was changed in my code that now it generates readme files in the Macintosh style of utf8, with CR\CR\LF as line endings, which in turn made a lot unnecessary spacing in my generated Readme files.

The Code is below:

   my $readme_tmpl = "README_tmpl.tt";
   if($os_type eq "LINUX") {
       $readme_tmpl = "README_tmpl_linux.tt";
   }
   my $data_dir = File::Spec->catdir($self->data_dir(), 'BuildSomething');
   $data_dir =~ s/\\/\//g;
   my $template = Template->new( INCLUDE_PATH => $data_dir );

   my %readme_params;

   $readme_params{build_app_name} = $pub_env->{BUILD_APP_NAME};
   $readme_params{project_name} = $self->project();

   $template->process($readme_tmpl, \%readme_params, $readme_file);

Where $readme_file is the path where the new file is going to be.

I am looking for ways to change it back to the Dos/Windows style of utf8 encoding, any ideas on how to do that?

Harvey Lin
  • 605
  • 9
  • 23
  • 2
    Can you please create a [mcve] that demonstrates your problem? Otherwise we just have to guess what's wrong with your code. – ThisSuitIsBlackNot Dec 27 '16 at 19:03
  • Added code, thanks for reminding. – Harvey Lin Dec 27 '16 at 19:14
  • 1
    UTF8 and the line endings are not related. Mac uses one CR. What you're seeing is a extra carriage return. That's probably not related to TT. Can you please also include one of the templates and example data that goes in? I believe either the template was edited to include additional CRs or your input now has line breaks where it didn't have them before. – simbabque Dec 27 '16 at 21:38
  • My template file only have one CR, as is my input, nothing else has changed. The output was right on windows systems just a few month ago, and something changed in the windows system that changed the output to have one more CR. I don't know what change caused this though. – Harvey Lin Dec 27 '16 at 21:52
  • 1
    If you think the change is on your system then we cannot help you diagnose it I'm afraid. – simbabque Dec 27 '16 at 22:02
  • Ok, this is what I think, doesn't mean it's what happened. The toolkit is generating utf 8 encoding files under a windows system using all windows settings, but the result file shows its encoding is utf 8 Macintosh, and the only difference is that it has an extra carriage return at the end of line. I checked the template files I use and it is in the right format. It really doesn't get more complicated than that. – Harvey Lin Dec 27 '16 at 23:43

1 Answers1

1

Problem solved, this post answers my question I get extra CR using TT (perl template toolkit)

I then set binmode => 1 on the process method and it worked.

Community
  • 1
  • 1
Harvey Lin
  • 605
  • 9
  • 23