Glenn & Curtis;

Thanks for the suggestions ... but more thanks to both you and Curtis for
helping me to start "thinking out of my box"... and this is why I'm replying
...

I have used both of your suggestions - the hash below and cgi html shortcuts
... I just needed to stop and invest a little time in a new tool - cgi - so
I ended up gutting the program ... reads a lot better with the shortcut once
you get use to them... both suggestions reduced the code by 50% or so.

I don't know if it's my version of cgi but the only thing I don't like about
the shortcuts is it doesn't generate "\n" so when you are working on the
html - the generated code - it's hard to read when you look at the source if
you didn't do something correct. Once it's working I wouldn't care in most
cases... (I could(did) physically put "\n" in as an element in the row for
the Tr but would be nice not to have to ... same with other shortcuts (and
again I did just add an element or entry where I wanted)... ) but it's REAL
nice not to have to remember the closing tag and I do like the way the
program reads once use get use to coding the shortcuts .... 

But I wanted to share with you an added benefit to the struct below ... I
have an other table 9 columns by n rows and build from a database... three
different tables yielding three columns each ...  I generated the form and
was looking and wanted to move one of the sets of columns to the left side
of the table ... Well, guess what... with your struct just change the
"sequence" and the table is regenerated with the columns moved ... no change
to the code except change 1,2,3 to 7,8,9 and  7,8,9 to 1,2,3...

Thanks again to both you & Curtis ... I hope others get some use out of this
also ....

PS...
Oh, thanks for reminding me about $_ ... I forget that Perl will help me if
I'll let it ... it gets old thinking of names for the foreach when you
really don't care what it returned ...  again just needed to "get out of my
box" ... bad habits are hard to break ! 

John W Moon 

-----Original Message-----
From: Tillema, Glenn [mailto:[EMAIL PROTECTED]]
Sent: June 15, 2001 18:56
To: 'Moon, John'; [EMAIL PROTECTED]
Subject: RE: How to generate a table ?


#!/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