Perlを中心とした技術系の話などをつらつら

2004年12月06日

Template::Toolkitのテンプレート内で割り算

Template::Toolkitのテンプレート内で割り算の商を取得したくて、

[% c = int (a / b) %]

などと直感的に書いてみたんですが、やっぱり構文エラーになってしまいました。しょうがなくマニュアルを眺めていると、以下のような記述が。

Template Toolkit Manual: Directives

The 'div' operator returns the integer result of division. Both '%' and 'mod' return the modulus (i.e. remainder) of division. 'mod' is provided as an alias for '%' for backwards compatibility with version 1.

[% 15 / 6 %] # 2.5

[% 15 div 6 %] # 2

[% 15 mod 6 %] # 3

[% c = a div b %]

でできるんですね。絶対忘れるのでメモ。

Technorati TAGTechnorati TAG , ,

Posted by horiuchi at 2004年12月06日 16:10

Continuing the discussion...

このエントリーのトラックバックURL:
http://hori-uchi.com/mt/trackback/236

Comments

Post a comment




Remember personal info?