I take a inside-out approach and use CGI's distributive magic for building the td and tr blocks.
#!/usr/bin/perl use warnings; use strict; use CGI; use constant COLS => 4; use constant ROWS => 5; use constant TABLE_SIZE => COLS * ROWS; my $cgi = new CGI; # Loop through the pages, to pretend we got a page number from a reque +st... foreach my $page_num ( 1 .. 6 ) { # Create a dummy list of image names. We're adding an orphan to test + a short # table display. my @image_names = map {"image_$_.jpg"} 1 .. 101; # ---------------------------------------- # this does the real work... # ---------------------------------------- # Get a page's table's worth of image names and wrap them inside < +img> # tags... my @imgs = map { $cgi->img($_) } splice( @image_names, ( $page_num - 1 ) * TABLE_SIZE, TABLE_SI +ZE ); # Make sure the table has enough elements. Add blank elements if not + to keep # the rows balanced... if ( scalar(@imgs) % COLS ) { push @imgs, ('&nbsp;') x ( COLS - ( scalar(@imgs) % COLS ) ); } # Read "THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS" in the CGI pe +rldoc. # # Process rows in column-sized chunks... my @rows = (); while (@imgs) { push @rows, join( '', $cgi->td( [ splice( @imgs, 0, COLS ) ] ) + ); } print $cgi->table( $cgi->Tr( \@rows ) ), "\n\n"; # ---------------------------------------- # end o' working part # ---------------------------------------- }

In reply to Re^2: printing out a table X wide and X down without html::template by gferguson
in thread printing out a table X wide and X down without html::template by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.