On Tue, 5 Feb 2002, Franco Bagnoli wrote:

> easy way of doing [% v = sqrt(2*g*h) %] or not?

Hmmm.  Have you considered passing a "sqrt" function to the contructor
hash


###############################

use Math::Complex; # allow for negative numbers

$tt2->process("mytemplate",
              {
                sqrt => sub { sqrt($_[0]) },
              });

###############################

Alternativly, you could create a "Maths" plugin that created maths
operators

##########################

package Template::Plugin::Maths;
use base qw(Template::Plugin);
use Math::Complex;

sub sqr
{
  my $self = shift;
  my $x    = shift;

  return sqrt($x)
}

1;

######################

[% USE Maths %]

The square root of -4 is [% Maths.sqr(-4) %]

######################

Hope this helps.

As for uniary minus, I suggest you create a "neg" operator that returns
the negative of that number

Mark.

-- 
  Mark Fowler
  Technology Developer
  http://www.indicosoftware.com/




Reply via email to