Perl Monk, Perl Meditation PerlMonks

### Template::Latex not interpolating variables . . .

by hesco (Deacon)
 on Feb 08, 2010 at 02:16 UTC Need Help??

hesco has asked for the wisdom of the Perl Monks concerning the following question:

I have a script which parses /etc/log/maillog and builds a hash of bounced email addresses, doing a few database interactions to identify the names and phone numbers of the recipients going without their email.

Today I'm adding Template::Latex to the mix to generate a report which might be useful for tracking down corrections to the bouncing email. But for some reason my variable substitutions are not happening.

My template includes the following:

[% FOREACH recipient IN call_list %]
\textbf{recipient.email} & box & recipient.uid: recipient.name & r
+ecipient.fname recipient.lname & recipient.phones \\
\hline
[% FOREACH sponsor IN call_list.recipient.upstream %]
[% END %]
\hline
[% END %]
[download]
The script itself includes:

sub produce_report {
my $call_list = shift; my$vars = { 'call_list' => $call_list }; print Dumper($vars);
$tt->process('nightly_bounced_emails_report.tex.tt2',$vars,
'bounced_email_report.pdf',
binmode => 1) || die $tt->error(); return; } [download]$call_list arrives as a hashref, with the bouncing email addresses used as keys, each containing a data structure for the bounced recipient, plus a key called 'upstream', which includes an arrayref of anonymous hashes for the folks who brought the bounced recipient into the mix.

When the template is processed, it is producing a .tex file including:

    \textbf{recipient.email} & box & recipient.uid: recipient.name & r
+ecipient.fname recipient.lname & recipient.phones \\
\hline

\hline

\textbf{recipient.email} & box & recipient.uid: recipient.name & r
+ecipient.fname recipient.lname & recipient.phones \\
\hline

\hline
[download]
And it never descends into the data structure to process the internal loop.

Any clues appreciated.

-- Hugh Esco

if( $lal &&$lol ) { $life++; } if($insurance->rationing() ) { $people->die(); } Replies are listed 'Best First'. Re: Template::Latex not interpolating variables . . . by ahmad (Hermit) on Feb 08, 2010 at 05:15 UTC All template variables should be put between [% %] to get processed Yes, of course. Thank you ahmad. I no longer get the literals passing through the filter, but my variables still are not being interpolated. Now I am seeing:  \textbf{} & box & : & & \\ \hline \hline \textbf{} & box & : & & \\ \hline [download] where my template now reads: [% FOREACH recipient IN call_list %] \textbf{[% recipient.email %]} & box & [% recipient.uid %]: [% rec +ipient.name %] & [% recipient.fname %] [% recipient.lname %] & [% rec +ip ient.phones %] \\ \hline [% FOREACH sponsor IN call_list.recipient.upstream %] \multicolumn{2}{||r|}{[% sponsor.email %]} & [% sponsor.uid %] +: [% sponsor.name %] & [% sponsor.fname %] [% sponsor.lname %] & [% s +po nsor.phones %] \\ [% END %] \hline [% END %] [download] if($lal && $lol ) {$life++; }
if( $insurance->rationing() ) {$people->die(); }

If your desired data is not shown, then you might be using the wrong data structure (Your hashref is not what you have expected).

Try using Data::Dumper to print out content of your hashref and see if it's indeed what you want.

If you still have problems with it, post the output of "print Dumper(\$call_list);" so I can have a look into it.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://821924]
Approved by GrandFather
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-03-24 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Which type of climate do you prefer to live in?

Results (60 votes). Check out past polls.

Notices?