FWIW, I updated the benchmarks to include that one. While not as slow as the nested loops in HTML::Template, it slower than the single loop in HTML::Template.
http://moc.rellimhsoj.com/perl/tmplloop_benchmark/ Benchmark: timing 40 iterations of Templateloop, perl, tmpl1loop, tmpl2loops... Templateloop: 18 wallclock secs (17.10 usr + 0.95 sys = 18.05 CPU) @ 2.22/s (n=40) perl: 0 wallclock secs ( 0.68 usr + 0.00 sys = 0.68 CPU) @ 58.82/s (n=40) (warning: too few iterations for a reliable count) tmpl1loop: 12 wallclock secs (11.78 usr + 0.06 sys = 11.84 CPU) @ 3.38/s (n=40) tmpl2loops: 41 wallclock secs (40.41 usr + 0.08 sys = 40.49 CPU) @ 0.99/s (n=40) Any other examples to throw in here? -- Josh I. On Thu, May 15, 2008 at 7:40 PM, Cees Hek <[EMAIL PROTECTED]> wrote: > On Fri, May 16, 2008 at 2:03 AM, Stephen Carville > <[EMAIL PROTECTED]> wrote: > > Is there any way to have a template where the number of columns is > > determined at run time? I know how to use TMPL_LOOP but that only > > lets me vary the number of rows. > > I realize that you are using HTML::Template, and you may be tied to it > for reasons good or bad, but > whenever I see people trying to bend a tool to do things against it's > will I feel obliged to show another way ;) > > In my example below, the data is provided in a format that is easy to > generate using a DBI call, and the template itself is pretty straight > forward. Row colouring is also made easy using the Cycle plugin (if > you want to alternate between three colours, just add another entry > into the cycle and leave the rest of the template as is). > > use Template; > > my $template = Template->new( POST_CHOMP => 1 ); > my $data = { > headers => [qw(col1 col2 col3 col4)], > rows => [ > [ qw(1.1 1.2 1.3 1.4) ], > [ qw(2.1 2.2 2.3 2.4) ], > [ qw(3.1 3.2 3.3 3.4) ], > [ qw(4.1 4.2 4.3 4.4) ], > [ qw(5.1 5.2 5.3 5.4) ], > [ qw(6.1 6.2 6.3 6.4) ], > ], > }; > $template->process(\*DATA, $data) or die $template->error; > __END__ > [% USE rowclass = Cycle('oddclass', 'evenclass') %] > <table> > <tr> > [% FOREACH col IN headers %] > <th>[% col %]</th> > [% END %] > </tr> > [% FOREACH row IN rows %] > <tr class="[% rowclass %]"> > [% FOREACH col IN row %] > <td>[% col %]</td> > [% END %] > </tr> > [% END %] > </table> > > > Cheers, > > Cees > > ##### CGI::Application community mailing list ################ > ## ## > ## To unsubscribe, or change your message delivery options, ## > ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ## > ## ## > ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## > ## Wiki: http://cgiapp.erlbaum.net/ ## > ## ## > ################################################################ > > ##### CGI::Application community mailing list ################ ## ## ## To unsubscribe, or change your message delivery options, ## ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp ## ## ## ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## ## Wiki: http://cgiapp.erlbaum.net/ ## ## ## ################################################################
