Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:

  • For parameter values, use CGI.pm always always always.
  • For small amounts of static HTML, generate the HTML tags however you want... I sometimes use both regular tags and CGI.pm tags interchangeably if I'm feeling lazy.
  • For non-static HTML more complicated than simple variable interpolation, save yourself the hassle and use CGI.pm.
  • For complicated formatting (like using tables for layout) or for large sites (i.e., your CGI is going to produce more than one completely different type of web page) you ought to use a template, either using a home-rolled regex solution (a la the solution in the Ram) or if your needs are more strenuous, one of the many modules.

Gary Blackburn
Trained Killer


In reply to Re: Should One Use CGI.pm to Generate HTML? by Trimbach
in thread Should One Use CGI.pm to Generate HTML? by sierrathedog04

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-18 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found