Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by veerubiji (Sexton)
on Nov 09, 2011 at 21:37 UTC ( #937229=note: print w/ replies, xml ) Need Help??


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

exactly you understand my problem.I want print as you said. I tried using .size also but still problems arising. can you see what tried using .size, I posted in main question.Can you tel what mistake i did and how to print data as i want.


Comment on Re^2: help me with template module to print like this
Re^3: help me with template module to print like this
by Eliya (Vicar) on Nov 09, 2011 at 23:01 UTC

    [% 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.

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

      regards, veerubiji.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://937229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-09-16 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (36 votes), past polls