fireartist has asked for the wisdom of the Perl Monks concerning the following question:
and would like to output a HTML table like so,@data = ( [1, 2, 3, 4, 5], ['one', 'two', 'three', 'four', 'five'], ['ein', 'zwei', 'drei', 'veir', 'funf'], ['hana', 'dool', 'set', 'net', 'dasut'], ['yi', 'er', 'san', 'si', 'wu'], );
I know how to manipulate the @data array to print it out like that,1 one ein hana yi 2 two zwei dool er 3 three drei set san 4 four veir net si 5 five funf dasut wu
outputsuse strict; use warnings; my @array = ([1, 2, 3, 4, 5], ['one', 'two', 'three', 'four', 'five'], ['ein', 'zwei', 'drei', 'veir', 'funf'], ['hana', 'dool', 'set', 'net', 'dasut'], ['yi', 'er', 'san', 'si', 'wu'],); my @sorted; my $i = 0; for (@array) { for ( @{$_} ) { push @{$sorted[$i]}, $_; $i ++; } $i = 0; } for (@sorted) { for ( @{$_} ) { print $_, ' ' } print $/ }
...so I do know how to manipulate the data, I just don't understand exactly what data structure HTML::Template requires.1 one ein hana yi 2 two zwei dool er 3 three drei set san 4 four veir net si 5 five funf dasut wu
Thanks!#!/usr/bin/perl -wT use strict; use CGI; $CGI::DISABLE_UPLOADS = 1; use CGI::Carp qw/fatalsToBrowser/; use HTML::Template; use vars qw/ $q $template $html @loop_data @data /; $q = new CGI; $html = do { local $/; <DATA> }; $template = HTML::Template->new(scalalref => \$html); @data = ( [1, 2, 3, 4, 5], ['one', 'two', 'three', 'four', 'five'], ['ein', 'zwei', 'drei', 'veir', 'funf'], ['hana', 'dool', 'set', 'net', 'dasut'], ['yi', 'er', 'san', 'si', 'wu'], ); ### DO SOMETHING HERE TO CREATE @loop_data ! $template->param(loop1 => \@loop_data); print $q->header; print $template->output; exit; __DATA__ <html> <body> <table> <!-- TMPL_LOOP NAME=loop1 --> <tr> <!-- TMPL_LOOP NAME=loop2 --> <td><!-- TMPL_VAR NAME=var1 --></td> <!-- /TMPL_LOOP --> </tr> <!-- /TMPL_LOOP --> </table> </body> </html>
|
|---|