in reply to Re^6: Fold a list using map splices
in thread Fold a list using map splices
I wonder if its even necessary to have a callback function.
package HTML::Table; use CGI; my $cgi = CGI->new(); sub map_rows (@) { my $n = splice(@_, 0, 1); push(@_, '' x (-@_ % $n)); my @table_rows = map {$cgi->Tr( $cgi->td( [splice @_, 0, $n] ) ) } 0..((@_/$n) - 1); } sub make_table { my ($columns, @elements) = @_; return $cgi->table( map_rows $columns, @elements ); } 1;
And the testing code
use HTML::Table; my $table = HTML::Table::make_table(5, qw[some random data to test th +e table creation thing] ); print $table;
Output
<table><tr><td>some</td> <td>random</td> <td>data</td> <td>to</ td> <td>test</td></tr> <tr><td>the</td> <td>table</td> <td>creation</t +d> <td>thing</td> <td></td></tr></table>
Or perhaps
| some | random | data | to | test |
| the | table | creation | thing |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Fold a list using map splices
by Aristotle (Chancellor) on Feb 20, 2006 at 18:42 UTC | |
|
Re^8: Fold a list using map splices
by Anonymous Monk on Apr 12, 2007 at 13:00 UTC |