Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
When using the HTML generation in CGI.pm remember it's not an all or nothing thing. Yes, if you find yourself doing a lot of HERE docs or a whole bunch of print p(b("Hello")." how are you?"); stuff you really really should be using a templating system. I'll even go as far as saying all static output should be templated. But CGI.pm makes it stupid simple to do some things that to me are awkward in a template... combining CGI.pm's generation functions with a templating system gets you the best of both worlds.

Suppose you've got a batch of data in an array that you want to display in an HTML list. To display it in a template you've got to create a suitable loop in your template, then assign your array data to a specially named loop variable that gets passed to your template engine. That's not that hard, but it's so much more easier for me to just my $list_var = ul(li(\@array)); and then plug $list_var into the appropriate part of my template.

Ditto with tables. If my data lends itself to the special array handling in CGI.pm it's so much easier to construct the table in code ($table = table(Tr(td(\@AoA)));) and plug the result into my template. This is ESPECIALLY true in very dynamic tables where the number of columns is not known ahead of time.

So, as always, use the parts of CGI.pm that make sense where they make sense, and leave the rest of the generation routines for when you want that quickie one-off and don't want to mess with a template.

Gary Blackburn
Trained Killer


In reply to Re: CGI.pm Disillusionment by Trimbach
in thread CGI.pm Disillusionment by Cody Pendant

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 perusing the Monastery: (6)
As of 2024-04-18 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found