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 |
In reply to Re^7: Fold a list using map splices
by hypochrismutreefuzz
in thread Fold a list using map splices
by hiseldl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |