Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did a quick testing with Perl 1.12.2 for MSWin32 Template module. It could handle all these substr operation properly. </p> <p>This is my test code:</p> <pre><code>use Template; # some useful options (see below for full list) my $config = { # DEFAULT_ENCODING =&gt; 'utf-8', INCLUDE_PATH =&gt; 'd:/devel/perl', # or list ref INTERPOLATE =&gt; 1, # expand "$var" in plain text EVAL_PERL =&gt; 1, # evaluate Perl code blocks }; # create Template object my $template = Template-&gt;new($config); # define template variables for replacement my $vars = { var1 =&gt; "abcdef" }; # specify input filename, or file handle, text reference, etc. my $input = 'ttmyfile.txt'; # process input template, substituting variables print $template-&gt;process($input, $vars); </code></pre> <p>ttmyfile.txt </p> <pre><code>Var = [% var1 %] [% string = "fööbär" -%] [% string.length %] # prints 6 [% string.substr(0, 5) %] # prints "fööbä" [% string.substr(0, 4) %] # prints "fööb" </code></pre> <p>Output:</p> <pre><code>Var = abcdef 6 # prints 6 fööbä # prints "fööbä" fööb # prints "fööb" 1 </code></pre> <p>All works fine, even without <code>use utf8</code> nor <code>DEFAULT_ENCODING</code>. Key things here:</p> <ol> <li><p>Make sure your template <code>.tt</code> files are encoded as UTF8 with <a href="http://linuxyz.blogspot.com/search/label/i18n" rel="nofollow">BOM -- <code>Byte Order Mark</code></a>. This is a must do task! Because Template-Toolkit is detect the Unicode file encoding according to BOM. </p> <ul> <li>You can use Windows Notepad to save a file with BOM, just do <code>File</code> --> <code>Save</code> --> Encoding: "UTF-8". </li> <li>You can use VIM make it as well by input <code>set fenc=utf8</code> and <code>set bomb</code>, then save the file, the file will start with BOM. </li> </ul></li> <li><p>Set the <code>NCODING</code> paramter <code>Template-&gt;new({NCODING =&gt; 'utf-8'});</code> as 'utf-8' will enforce <code>Template</code> to load template file as 'utf-8'.</p></li> <li><p>Suggest to have <code>use utf8</code> in your script, it will ensure all your inline strings are encoding as utf8 properly.</p></li> </ol> <p>Because <code>Catalyst::View::TT</code> rely on Template, I believe it should be working as well! Good luck~~~</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload