in reply to printing out a table X wide and X down without html::template

Really you only need to define the number of columns. The rows will be dynamically determined based on how many images you have. Modulo is the way to go in this scenario:

#!/usr/bin/perl # run this like: # foo.pl <number_of_cols> # foo.pl 5 use strict; # get user input for the number of columns my $cols = $ARGV[0] || 2; my @images = qw(1.gif 2.gif 3.jpg 4.png 5.jpg); my $pos = 0; my $row = 0; my @rowdata; foreach my $file (sort @images) { $rowdata[$row][$pos] = qq|<tr>\n| if $pos == 0; $rowdata[$row][$pos] .= qq| <td><img src="$file">$file</td>|; if (($pos > 0 && $pos % ($cols-1) == 0) || $cols == 1) { # we just filled the last position. Reset. $rowdata[$row][$pos] .= qq|\n</tr>\n|; $pos = 0; $row++; } else { $pos++; } } unless ($pos == 0) { $rowdata[$row][$pos++] = qq| <td>&nbsp;</td>| until $pos == $cols; $rowdata[$row][$pos] .= qq|</tr>\n|; } print join("\n",@{$_}) for @rowdata;

I'm sure that can be golfed down much smaller.

blahblah