rastoboy has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Monks,

I'm new to CGI scripting, and so I'm wondering if there's an elegant way to include all those other languages in my output. Right now I have stuff that looks like this:

print "<table cellspacing = 8 border = 1>"; my $count = 1; print "<tr><td>None of these--what I entered was correct:<p>Company: $ +original_address->{'company'}<br>Name: $original_address->{'addressee +'}<br>Street: $original_address->{'street'}<br>Street2: $original_add +ress->{'street2'}<br>Suite: $original_address->{'unitNumber'}<br>City +: $original_address->{'city'}<br>State: $original_address->{'state'}< +br>Zipcode: $original_address->{'zipCode'}<br></td><td><input type=\" +radio\" name=\"addresslist\" value=\" $count \"></td><td><p class=\ +"form_submit_action\"><input id=\"order\" value=\"Submit\" type=\"sub +mit\" /></td></tr>"; etc.
...and this is just for my proof of concept version. When my company's web designers get involved there's going to be all kinds of javascript/css in place of the above, and I just can't help thinking that this is ugly, hard to read code. However, it doesn't appear that CGI.pm has all the functionality they're going to want for outputting their pretty js/css code. Any best practices to guide me would be very much appreciated!

Replies are listed 'Best First'.
Re: CGI and writing html/javascript/css elegantly
by spx2 (Deacon) on Nov 11, 2009 at 04:32 UTC
      Cool, thanks spx2!
Re: CGI and writing html/javascript/css elegantly
by Unforgiven (Hermit) on Nov 11, 2009 at 16:29 UTC

    Others mentioned using a framework, but if you don't, at the very least, use a template engine like HTML::Template or Template Toolkit.

    As a general rule, I consider it a bad sign when there's any HTML in the script at all, ever. Keep presentation and code separate. It makes things much easier, especially over time, and especially for someone else just picking up your code for the first time.

Re: CGI and writing html/javascript/css elegantly
by leocharre (Priest) on Nov 11, 2009 at 14:35 UTC
Re: CGI and writing html/javascript/css elegantly
by Anonymous Monk on Nov 11, 2009 at 16:39 UTC
    I have had great success with: CGI::Application + CGI::Application::Plugin::AnyTemplate utilizing Template::Toolkit
      Cool, thanks again all!
        Awesome. For my simple project Template Toolkit will get the job done nicely. Thanks again!