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>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.