I am a novice using the template toolkit for the first time. To understand
how the toolkit works I installed it and tried the example provided at
Perl.com site by O'Reilly.

The code looks straightforward and easy to understand. However when I run
the code the output is not as illustrated in the example. 

The code in the (.pl) file:

#!usr/local/bin/perl 

use Template;

my $tt= Template->new;

$tt->process('my_template', \%data) || die $tt->error;

my @teams = ({ name   => 'Man Utd',
               played =>  16,
               won    =>  12,
               drawn  =>  3,
               lost   =>  1 
             },
             { name   =>  'Liverpool',
               played =>  15,
               won    =>  11,
               drawn  =>  2,
               lost   =>  1 
             }
            );



my %data = ( name   => 'English Premier League',
             season => '2000/01',
             teams  => \@teams );

-------------------- End of code in pl file ---------------

The template I am using (which is called "my_template") in the code above:
is: 

League Standings

League Name: [% name %]
Season     : [% season %]

Teams:
[% FOREACH team = teams -%]
[% team.name %] [% team.played -%]
[% team.won %] [% team.drawn %] [% team.lost %]
[% END -%]



The end result is:


C:\perl_code>perl league.pl

League Standings

League Name:
Season     :

Teams:

Basically the headers in the template are output to the screen but the data
is not. 

I am sorry if this is a trivial problem for most of you but I am a beginner
to Perl and would appreciate a little help here.

Best Rgds

Avi Rao



Reply via email to