in reply to Template toolkit binary operations

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

Replies are listed 'Best First'.
Re^2: Template toolkit binary operations
by nikos (Scribe) on Oct 09, 2004 at 21:06 UTC
    Thank you for your reply. I'll edit my post. Using Perl to do the trick is fine. I just thought there would be an easier way. I need something like [% IF a & 1 == 1 %]thumbnail[% ELSE %]picture[% END %].