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

Er. I beg to differ:
use CGI; use strict; use warnings; print Tr ({align => "CENTER", valign=>"TOP", BGCOLOR=>"blue", font-color=> "yellow", FONT-FAMILY=> "verdana,arial,helvetica", FONT-SIZE=> "12"}); print Tr (-align => "CENTER", -valign=>"TOP", -BGCOLOR=>"blue", -font-color=> "yellow", -FONT-FAMILY=> "verdana,arial,helvetica", -FONT-SIZE=> "12"); __END__ Bareword "font" not allowed while "strict subs" in use at C:\Temp\oops +.pl line 5. Bareword "FONT" not allowed while "strict subs" in use at C:\Temp\oops +.pl line 5. Bareword "FONT" not allowed while "strict subs" in use at C:\Temp\oops +.pl line 5. Execution of C:\Temp\oops.pl aborted due to compilation errors.
because of the hash key quoting rules that I mentioned earlier...

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Re: Re: HTML and CGI coding
by hbradshaw (Novice) on Dec 09, 2002 at 15:11 UTC
    Hello: Well, I never realized that trying to change a font color, size, and face was going to cause so much controversy...:) Anyway, I've been modifiying my code and right now it looks as such, I included the whole section of code so you can see what's happening:
    push (@row, Tr ({"-align" => "CENTER", "-valign" => "TOP", "-BGCOLOR" => "blue", "-font-color" => "yellow", "-FONT-FAMILY" => "verdana, +arial,helvetica", "-FONT-SIZE" => "12"}, + th ("I +tem"), th ("Quantity"), th ("Description"), th ("Unit Price"), th ("Price") )); foreach my $item_id (sort (keys (%{$cart_ref}))) { my $item_ref = $cart_ref->{$item_id}; my $total_item_price = $item_ref->{qty} * $item_ref->{price}; $total_price += $total_item_price; # generate a link allowing the item to be deleted from the car +t my $url = sprintf ("%s?choice=delete;item_id=%s", url (), escape ($item_id)); push (@row, Tr ( td (escapeHTML ($item_id)), td (escapeHTML ($item_ref->{qty})), td (escapeHTML ($item_ref->{description})), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $item_ref->{price +}))), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_item_price +))), + ($show_links ? td (a ({-href => $url}, img ({-src => "../im +ages/delete.jpg", -border => "0"}))) + : td (" ")) )); } push (@row, Tr ( td ({-colspan => "2"}, ""), td ({-colspan => "2"}, "Total"), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_price))) )); return (table ({-border => 0}, @row)); }
    Now, I believe I've incorporated lots of the suggestions but my row with headings have the blue background but it still doesn't want to take the new font color, size, or face. At least I'm not getting any error messages. Any other thoughts are greatly appreciated.

      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.

        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.
      Hi hbradshaw,

      as I pointed out in my earlier post, you should choose either
      Tr( -attr => "value", "-foo-bar" => "baz" )

      ie, attributes have leading hyphens, are quoted if contain inline hyphens, and are not surrounded by {} brackets,
      or
      Tr({ attr => "value", "foo-bar" => "baz" })

      ie, attributes have no leading hyphen, but are contained within {} brackets, making it an anonymous hash. Strings with inline hyphens should still be quoted

      The easiest way to fix your code above is to remove the {} brackets from within your Tr().

      hope this helps

      thinker
      Hi hbradshaw, im afraid my involvement in this thread is restircted to the quoting of hash keys. There are others far more able to advise you on the correct uage of CGI than I am.

      Good luck however, and a little thought, you may find perltidy from sourceforge (dont have a link handy sorry) to be a useful addition to your tool kit.

      Regards,

      --- demerphq
      my friends call me, usually because I'm late....