Perhaps I'm doing something stupid, but I don't understand why the the
template below does not work as I'd expect.  The problem appears to be
something to do with the NEXT statement.  I would have expected both first
names in the mylist hash to have been printed out.  Instead only susi is
printed out.  Both first names are printed out, if I change the dayofweek
value i.e. the NEXT statement is not processed.

I'd be grateful if someone could point out where I'm going wrong.

Perl version 5.6.1 (Activestate) and Template downloaded and installed today
(2.02).

Thanks.  Anthony Jordan

use strict;
use Template;

my $templatetext = << 'EOT';
[% dayofweek = 'monday' %]
[% mylist.fred.gender = 'male' %]
[% mylist.susi.gender = 'female' %]
[% FOREACH firstname = mylist.keys %]
[% SWITCH dayofweek %]
[% CASE 'monday' %]
It is monday
[% firstname %] is [% mylist.$firstname.gender %]
[% NEXT IF mylist.$firstname.gender != 'male' %]
Monday stuff here for males
[% CASE DEFAULT %]
[% firstname %] is [% mylist.$firstname.gender %]
Other day of the week stuff here
[% END %]
End of switch statement
[% END %]

EOT

my $t = Template->new;
$t->process(\$templatetext) or die $t->error;


Reply via email to