in reply to Should One Use CGI.pm to Generate HTML?

When I first started using CGI.pm I had the same thought as you... templating issues aside (you should use a template system of some sort for large blocks of HTML) what's the big difference between print h1("Hello World"); and print "<h1>Hello World</h1>";. I mean, really.

But as time passed the light went on and I realized that CGI.pm really does make life easier in HTML generation... not for big blocks of static HTML but for all those dynamic things that you're probably using a CGI for in the first place.

For example, think about writing the HTML for a form with checkboxes where some of the checkboxes are pre-checked. Which checkboxes are checked depends on logic within your CGI. If you try to do this using print statements and non-CGI.pm generated HTML you're going to spend an enormous amount of time dealing with if/then statements to determine if "CHECKED" should appear in your static HTML or not. Using CGI.pm it's as simple as passing references to a couple of arrays and you're done. Piece of cake. CGI.pm also makes auto-generation of table tags a total breeze.

In short my vote is:

Gary Blackburn
Trained Killer

Replies are listed 'Best First'.
Re: Re: Should One Use CGI.pm to Generate HTML?
by puck (Scribe) on Jan 01, 2001 at 15:12 UTC
    I use CGI.pm for accessing params and for generating forms. This isn't just to make the logic simpler when generating checkboxes, but mostly because it remembers settings for you.

    This is useful when a user submits a form, but with some fields not filled in. The code generates a warning message which is displayed and then I just call the function to generate the form again and hey presto, everything the user entered is there. Very useful.

    I don't use CGI.pm for generating the rest of my HTML code though, I prefer to that by hand.