[Petal] compiled expression (again)
Fergal Daly
fergal at esatclear.ie
Thu Jun 19 15:09:07 BST 2003
On Thursday 19 June 2003 11:25, Jean-Michel Hiver wrote:
> Or maybe $res .= defined $hash->{"user"} ? $hash->{"user"} : "";
>
> If only we'd have the ?? operator that Larry refused to implement :)
Yeah that would solve it nicely.
The problem with
$res .= defined $hash->{"user"} ? $hash->{"user"} : "";
is that we end up evaluating the expression twice, which is slow. Worse still
is if the expression invokes a method that has side effects for (an extreme)
example
$hash->{"user"}->{"creditcard"}->debit(10);
you can run into problems. I think if the expression appears once in the
template it should only be evaluated once, otherwise subtle bugs can occur.
That leaves 3 ways
* $res .= define($hash->{"user"});
* $res .= do {my $v = $hash->{"user"}; defined($v) ? $v : ""};
* $res .= $hash->{"user"}; with warnings turned off
I think turning off warnings is easiest and fastest and seems harmless to me
as long as it's configurable and they are turned on by the test suite. The
warnings would only be turned off inside the template code,
F
More information about the Petal
mailing list