What's in top_menu? I can imagine it's something like this:

$top_menu = { base_name => 'foo', size => 23 };

And after your code executes, you expect width = 3.03 and extra = 0. Yes?

What your code actually does is something different. To get the base_name element in a top_menu hash in TT, it's top_menu.base_name (no dollar sign). If you say top_menu.$base_name in TT, it's like $top_menu[$base_name] in Perl.

I could be wrong about this, however. I'd expect top_menu.$size to be zero if you haven't set size to anything in particular, so I'd expect 100/top_menu.$size to bomb out as division by zero. Also, the error you're getting isn't really explained by what I'm talking about.

Anyway, I think a Data::Dumper look into your variables might help.

I also wonder if it would help to explicitly say

[%- SET extra = ((100-(width*(top_menu.$size)))/2); -%]

...although I'm not sure why that would help.


In reply to Re: Math in Template::Toolkit by kyle
in thread Math in Template::Toolkit by talexb

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.