in reply to Re: Re: Re: HTML and CGI coding
in thread HTML and CGI coding

As I stated before, I think you'd be much better off learning and using CSS for your markup than trying to do it with CGI. You'll get much more consistent results and changes will be a lot easier to make since you'll only have to change one thing in a style sheet rather than who knows how many things in your perl program. Alternately, look into producing your HTML output with HTML::Template rather than CGI. That method would also separate your presentation from your program logic.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: HTML and CGI coding
by hbradshaw (Novice) on Dec 09, 2002 at 16:19 UTC
    Hi! Unfortunately, I'm not familiar with either CSS or HTML::Template. I'll look into it but I'm not sure where to start.
      Whether or not HMTL::Template is a better choice than CGI.pm is really up to you, but definetly look into CSS! In the meantime, here is a watered down version of your problem that uses HTML::Template instead (be sure and check out our HTML::Template Tutorial for some lessons on the basics).
      use strict; use CGI qw(header); use HTML::Template; my $cart_ref = { 42 => { qty => 5, price => 5, description => 'widget 42', }, 77 => { qty => 2, price => 7, description => 'widget 77', }, }; my $html = do {local $/;<DATA>}; my $tmpl = HTML::Template->new(scalarref=> \$html); my $rows = [ map { { id => $_, %{$cart_ref->{$_}} } } keys %$cart_ref ]; $tmpl->param(rows => $rows); print header, $tmpl->output; __DATA__ <table> <tr> <th>Item</th> <th>Quantity</th> <th>Description</th> <th>Price</th> </tr> <tmpl_loop rows> <tr> <td><tmpl_var id></td> <td><tmpl_var qty></td> <td><tmpl_var description></td> <td><tmpl_var price></td> </tr> </tmpl_loop> </table>

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)