in reply to Control break with Template::Toolkit

It's possible, but I'm not sure the template is the best place to put logic into:
#!/usr/bin/perl use warnings; use strict; use Template; my $template = 'Template'->new; my @reclist = ([1, 2, 'A', 4], [3, 4, 'A', 5], [5, 5, 'B', 2], [6, 2, 'B', 3], [1, 2, 'C', 2], [2, 3, 'C', 2], [1, 3, 'C', 1]); $template->process(\( join "", <DATA>), {reclist => \@reclist}); __DATA__ [% lastcat = "" %] [% FOREACH catrec IN reclist %] [% IF lastcat != catrec.2 %][% catrec.2 %][% lastcat = catrec.2 %][ +% END %] [% FOREACH rec IN catrec %] [% rec %] [% END %] [% END %]
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Control break with Template::Toolkit
by haj (Vicar) on Nov 14, 2019 at 01:02 UTC
    ...but I'm not sure the template is the best place to put logic into:
    MVC enthusiasts may enjoy heated debates about this, but in my opinion those doubts aren't worth their time. I'd easily argue that the desired output is a matter of data presentation and not a matter of logic, so a template is a quite appropriate place. We both have demonstrated that TT is quite capable of doing the transformation :)