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

This example uses Perl::CGI

#!/usr/bin/perl -w use warnings; use strict; package main; # # I really like Perl::CGI -- so this example incorporates it. # use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; my $human_legible = "\n"; print $q->header, $q->start_html('Table Example'), $q->h1('How to Format a table'); # # Add breaks so ppl can read the HTML output. # This is an example after all. # print $human_legible; # # This is where we figure out spacing. It could be made into a # function easily enough. # my $x_dim = 4; my $y_dim = 5; my $test_text = "This is a test"; my @array = ( $test_text, $test_text, $test_text, $test_text, $test_text, $test_text, $test_text ); my $table_rows = int((scalar @array) / $x_dim); my $last_row_count = (scalar @array) % $x_dim; # # Print the table here. # print $q->start_table; my $array_index = 0; my $table_entries = ""; for ( my $r = 0; $r < $table_rows; $r++ ) { $table_entries = ""; for ( my $j = 0; $j < $x_dim ; $j++ ) { $table_entries .= $q->td($array[$array_index]); $array_index++; } print $q->Tr($table_entries); print $human_legible; } $table_entries = ""; for ( my $i = 0; $i < $last_row_count ; $i++ ) { $table_entries .= $q->td($array[$array_index]); $array_index++; } print $q->Tr($table_entries); print $human_legible; print $q->end_table; print $q->end_html;
The output is:

C:\Code>perl cgitable.pl Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Table Example</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <h1>How to Format a table</h1> <table><tr><td>This is a test</td><td>This is a test</td><td>This is a + test</td> <td>This is a test</td></tr> <tr><td>This is a test</td><td>This is a test</td><td>This is a test</ +td></tr> </table> </body> </html>