Hi there:
Yes, I tried it. The filled variables in the template in the first call became null in the second call of fill_in. The template only got the value of variables used in the second call of fill_in.
Here is the template
It has come to our attention that you are delinquent in your
{$monthname[$last_paid_month]} payment. Please remit
${sprintf("%.2f", $amount)} immediately, or your patellae may
be needlessly endangered.
Love,
Mark "Vizopteryx" Dominus
Here is the script
#!/usr/bin/perl5.6
use Text::Template;
my $template = Text::Template->new(SOURCE => 'formletter.tmpl')
or die "Couldn't construct template: $Text::Template::ERROR"
+;
my @monthname = qw(January February March April May June
July August September October November Dece
+mber);
my %vars1 = (title => 'Mr.',
last_paid_month => 1, # February
amount => 392.12,
monthname => \@monthname,
);
my $result = $template->fill_in(HASH => \%vars1);
if (defined $result) { print $result }
else { die "Couldn't fill in template: $Text::Template::ERROR" }
my %vars2 = (title => 'Mr.',
firstname => 'Bill',
lastname => 'Gates',
);
$result = $template->fill_in(HASH => \%vars2);
if (defined $result) { print $result }
else { die "Couldn't fill in template: $Text::Template::ERROR" }
Here is the output
Dear Mr. ,
It has come to our attention that you are delinquent in your
February payment. Please remit
$392.12 immediately, or your patellae may
be needlessly endangered.
Love,
Mark "Vizopteryx" Dominus
Dear Mr. Gates,
It has come to our attention that you are delinquent in your
payment. Please remit
$0.00 immediately, or your patellae may
be needlessly endangered.
Love,
Mark "Vizopteryx" Dominus
<edit: castaway: added code tags> |