Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use feature qw{ say state } ;
- use strict ;
- use warnings ;
- use Data::Dumper ;
- my @alphabet = 'a' .. 'z' ;
- my $table ;
- for my $i ( 1 .. 10 ) {
- my $row ;
- for my $j ( 1 .. 10 ) {
- my $l = shift @alphabet ;
- push @$row, $l ;
- push @alphabet, $l ;
- }
- push @$table, $row ;
- }
- if ( 1 ) {
- use Template ;
- say '=' x 40 ;
- say 'Template Toolkit' ;
- my $template = <<'TT';
- <table>
- <tbody>
- [% FOREACH row IN table -%]
- <tr>
- [% FOREACH cell IN row -%]
- <td>[% cell %]</td>
- [% END -%]
- </tr>
- [% END -%]
- </tbody>
- </table>
- TT
- my $config = {
- POST_CHOMP => 0,
- ABSOLUTE => 1,
- RELATIVE => 1
- } ;
- my $object = { table => $table } ;
- my $tt = Template->new( $config ) ;
- $tt->process( \$template, $object )
- || die "Template process failed: ", $tt->error(), "\n" ;
- }
- if ( 1 ) {
- say '=' x 40 ;
- say 'Handlebars' ;
- use Text::Handlebars ;
- my $hb = Text::Handlebars->new() ;
- my $vars = { table => $table } ;
- my $template = <<'HB';
- <table>
- <tbody>
- {{#each table}}
- <tr>
- {{#each this }}
- <td>{{this}}</td>
- {{/each}}
- </tr>
- {{/each}}
- </tbody>
- </table>
- HB
- say $hb->render_string( $template, $vars ) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement