#! perl -slw use strict; use CGI qw[td Tr :table caption]; sub mapn (&@) { my($c, $n, $s) = (shift, shift, 0); map{ $s+=$n; $c->( @_[($s-$n) .. ($s < @_ ? $s-1 : @_-1) ] ); } 0 .. (@_/$n); } sub mapnz (&@) { my($c, $n, $s) = (shift, shift, 0); map{ $s+=$n; $c->( @_[($s-$n) .. ($s - 1) ] ); } 0 .. (@_/$n); } my @tabular_data = map{ 1000+int rand 8999 } 1 .. 31; print table( {border=>1}, $/, mapn{ Tr( td( \@_ ) ).$/; } 5, @tabular_data ); print table( {border=>1}, $/, caption('Columns: ' . $_), $/, mapnz{ Tr( td( \@_ ) ).$/ } $_, @tabular_data ) for 3 .. 8; __END__ C:\test>236799
4978 7782 3230 3524 7570
9627 4424 7968 2523 1838
9843 8797 5034 8499 3683
5591 2402 6131 2649 5917
1333 7874 7031 2269 3766
2151 1350 7235 5986 1447
2627
Columns: 3
4978 7782 3230
3524 7570 9627
4424 7968 2523
1838 9843 8797
5034 8499 3683
5591 2402 6131
2649 5917 1333
7874 7031 2269
3766 2151 1350
7235 5986 1447
2627