Perl Template with strict option: how to check whether a variable is defined?

Viewed 264

The following code dies with a var.undef error because var is not defined. It works if I change the STRICT option to 0, but I'd like to keep strict checks, unless it's in an [% IF var %] check in the template. How do I do that?

use strict;
use warnings;
use Template;

my $t = Template->new(STRICT => 1) || die Template->error();
my $template = '[% IF var %][% var %][% END%]';
my $output = '';
$t->process(\$template, {}, \$output) || die $t->error(), "\n";
print "$output\n";
1 Answers
Related