The Template Toolkit language isn't really perl. It is primarily about text substitution, not computation. It's possible to embed real perl in a template with the PERL directive. Here's your code with that modification,

#!/usr/bin/perl -w use strict; use Template; my $template=new Template( EVAL_PERL => 1); $template->process(\*DATA) || die $template->error; __DATA__ 8 and 1 = [% PERL %] print 8 & 1 [% END %] (should be 0, if we use a b +inary operator) 8 or 1 = [% PERL %] print 8 | 1 [% END %] (should be 9, if we use a bi +nary operator)
When run, that produces,
$ perl ttbin.pl 8 and 1 = 0 (should be 0, if we use a binary operator) 8 or 1 = 9 (should be 9, if we use a binary operator) $
"Binary operator" usually refers to an op with two arguments, usually with infix semantics. We usually call the operators you wanted "bitwise". In perl, and and or are low-precedence versions of the logical operators && and ||.

After Compline,
Zaxo


In reply to Re: Template toolkit binary operations by Zaxo
in thread Template toolkit binary operations by nikos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.