in reply to reading all images in a directory

$i = 1; print "<tr>"; for ( @images ) { print "<td>"; # print image print "</td>" print "</tr><tr>" if !$i++%5; } print "</tr>";
(Untested)

Replies are listed 'Best First'.
Re^2: reading all images in a directory
by ikegami (Patriarch) on Jun 24, 2005 at 17:52 UTC

    You have a blank trailing row if the number of images is divisible by 5. Fix:

    $i = 0; $open = 0; foreach (@images) # or: while ($sth->fetch) # or: while (readdir(IMAGE_DIR)) { (print "<tr>", $open = 1) unless $open; print "<td>"; # print image print "</td>" (print "</tr>", $open = 0) unless ++$i % 5; } print "<tr>" if $open;

    As a bonus, I wrote the fix such that you don't have to know how many images there are in advance (just like in the original solution). This is very useful when reading from a database.