Advertisement
Guest User

Untitled

a guest
May 27th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use feature qw{ say state } ;
  4. use strict ;
  5. use warnings ;
  6.  
  7. use Data::Dumper ;
  8.  
  9. my @alphabet = 'a' .. 'z' ;
  10.  
  11. my $table ;
  12.  
  13. for my $i ( 1 .. 10 ) {
  14. my $row ;
  15. for my $j ( 1 .. 10 ) {
  16. my $l = shift @alphabet ;
  17. push @$row, $l ;
  18. push @alphabet, $l ;
  19. }
  20. push @$table, $row ;
  21. }
  22.  
  23. if ( 1 ) {
  24. use Template ;
  25. say '=' x 40 ;
  26. say 'Template Toolkit' ;
  27. my $template = <<'TT';
  28.  
  29. <table>
  30. <tbody>
  31. [% FOREACH row IN table -%]
  32. <tr>
  33. [% FOREACH cell IN row -%]
  34. <td>[% cell %]</td>
  35. [% END -%]
  36. </tr>
  37. [% END -%]
  38. </tbody>
  39. </table>
  40.  
  41. TT
  42.  
  43. my $config = {
  44. POST_CHOMP => 0,
  45. ABSOLUTE => 1,
  46. RELATIVE => 1
  47. } ;
  48. my $object = { table => $table } ;
  49. my $tt = Template->new( $config ) ;
  50. $tt->process( \$template, $object )
  51. || die "Template process failed: ", $tt->error(), "\n" ;
  52. }
  53.  
  54. if ( 1 ) {
  55. say '=' x 40 ;
  56. say 'Handlebars' ;
  57. use Text::Handlebars ;
  58. my $hb = Text::Handlebars->new() ;
  59. my $vars = { table => $table } ;
  60. my $template = <<'HB';
  61.  
  62. <table>
  63. <tbody>
  64. {{#each table}}
  65. <tr>
  66. {{#each this }}
  67. <td>{{this}}</td>
  68. {{/each}}
  69. </tr>
  70. {{/each}}
  71. </tbody>
  72. </table>
  73.  
  74. HB
  75.  
  76. say $hb->render_string( $template, $vars ) ;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement