#!/usr/local/bin/perl -w

use CGI qw/:standard *table/;

$cust_id = "cust";
$acct = "account";
$title = "title";

%hofEntries = (1 => {label => "Customer Id",
                     name  => "NEWCUST_ID",
                     def => $cust_id,
                     size => "10",},
               2 => {label => "Account",
                     name => "NEWACCT",
                     def => $acct,
                     size => "15",},
               3 => {label=> "Title",
                     name => "NEWTITLE",
                     def => $title,
                     size => "15",});

$q = new CGI;

print header,
      start_html;

print start_table;

foreach (sort keys %hofEntries) {
   print Tr(td({-align=>RIGHT},
               $hofEntries{$_}{'label'},b(':')),
            td({-align=>LEFT},
               $q->textfield(-name=>$hofEntries{$_}{'name'},
                            '-default'=>$hofEntries{$_}{'def'},
                             -size=>$hofEntries{$_}{'size'},
                             -maxlength=>$hofEntries{$_}{'size'})));
}

print end_table;
print end_html;


I noticed that you kept repeating the same things over and over so I shoved 
the table contents into a loop. For three entries it doesn't really save you a lot of 
space but as your number of entries increase it will.

I'm sure someone else can come up with a better way of loading the hash to make it 
even simpler ...


cheers,
Glenn

Glenn Tillema                  [EMAIL PROTECTED]
ADC Telecommunications, Inc. 
PO Box 1101, MS 508
Minneapolis, MN  55440-1101
Learn about ADC - The Broadband Company - www.adc.com

> -----Original Message-----
> From: Moon, John [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 15, 2001 5:08 PM
> To: [EMAIL PROTECTED]
> Subject: How to generate a table ?
> 
> 
> Could someone please suggest a "simpler" way to generate this 
> table ...
> 
> print
> '<table>',
>     '<tr>',
>         '<td align="right">',
>             'Customer Id <B>:</B> ',
>         '</td>',
>         '<td align="left">',
>             $q->textfield(-name=>'NEWCUST_ID', 
> -default=>$cust_id,-size=>10,
> -maxlength=>10),
>         '</td>',
>     "</tr>\n",
>     '<tr>',
>         '<td align="right">',
>             'Account <B>:</B> ',
>         '</td>',
>         '<td align="left">',
>             $q->textfield(-name=>'NEWACCT', -default=>$acct, 
> -size=>15,
> -maxlength=>15),
>         '</td>',
>     "</tr>\n",
>     '<tr>',
>         '<td align="right">',
>             'Title <B>:</B> ',
>         '</td>',
>         '<td align="left">',
>                 $q->textfield(-name=>'NEWTITLE',-default=>$title,
> -size=>50,-maxlength=>100),
>         '</td>',
>     "</tr>\n",
> "</table>\n";  
> 
> John W Moon
> 

Reply via email to