It's not that pretty, but
$template->param(
some_var => 10,
(some_var => $hash{some_possibly_undefined_key}) x!! exists($hash{so
+me_possibly_undefined_key}),
);
will do what you want. Or
$template->param(
some_var => exists $hash{some_possibly_undefined_key} ? $hash{some_p
+ossibly_undefined_key} : 10;
);
However, you might also try using
Params::Validate
{
package MyTemplate;
use base Template;
use Params::Validate qw (validate);
sub param
{
my $self = shift;
my %p = validate(@_, {
some_var => {
default => 12,
}
});
$self->SUPER::param(%p);
}
}
To actually answer your question, some things are hard to protect
against and it is best to just try to avoid some constructs.
For example you can write
if ($a == 0)
or you can write
if (0 == $a)
using the second will keep you from the problem of writing
if ($a = 0).
-- gam3
A picture is worth a thousand words, but takes 200K.