in reply to Re^2: help me with template module to print like this
in thread help me with template module to print like this

[% LAST %] is not the same as loop.last().

The data you've shown is a little too messy for me (to try to fix it up to actually match its usage in the given template...), but the general idea would be something like this:

my $data = { employee => [ { name => 'Foo' }, { name => 'Bar' }, { name => 'Baz' }, ] }; my $template = Template->new(); $template->process(\*DATA, $data) || die "Template process failed: ", $template->error(), "\n"; __DATA__ [% FOREACH person IN employee %] [%- IF loop.index() %][% loop.size()>2 && loop.last() ? ' or':',' +%] [% END %] [%- person.name %] [%- END %].

Output:

Foo, Bar or Baz.

Replies are listed 'Best First'.
Re^4: help me with template module to print like this
by veerubiji (Sexton) on Nov 10, 2011 at 08:25 UTC

    Hi Eliya, Thank you for providing such example, That is working, my problem is solved. Thank you very much.

    regards, veerubiji.