(This has also been posted to the Template mailing list)
I recently had a bug in a Web page where if we had a single digit day, Template Toolkit v2.08 was failing a conditional check to see if it matched its numeric equivalent. I suspect that this is caused by Template Toolkit using eq when an == is found in the document. This causes 3 == '03' to evaluate as false and violates the DWIM principle.
Is this a known issue, mentioned somewhere in the docs, or just a bug? Below is a short test script that demonstrates the problem.
#!/usr/bin/perl -w use strict; use Template; my $template = Template->new; my %data = ( foo => 3, bar => '03' ); print "Perl results: ", $data{ foo } == $data{ bar } ? "match\n" : "no match\n"; $template->process( \*DATA, \%data ); __DATA__ Template results: [% foo == bar ? 'match' : 'no match' %]
I fixed the problem in my code by forcing 'bar' to be numeric.
Template results: [% foo == bar+0 ? 'match' : 'no match' %]
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to 'eq' vs '==' inTemplate Toolkit by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |