Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: OUTPUT: inline or template_based?

by George_Sherston (Vicar)
on May 28, 2002 at 10:41 UTC ( [id://169731]=note: print w/replies, xml ) Need Help??


in reply to OUTPUT: inline or template_based?

There are several advantages to templates (HTML::Template is my fave, and a popular choice), among which on emight include:
  • easy to cannibalise existing HTML
  • re-usable (bits that crop up in page after page can have their own, single, template)
  • easy to change "skins"
  • data hiding - pushes the formatting choices into their own space where you can forget about them
  • easier to handle situations where you've got lots of different things that you might output in the same format
Having said that, for short and simple data output, I agree that the overhead in setting up the template (overhead in terms of that most important=to-optimise variable, developer time) sometimes makes one want to dump it straight into the code.

In this case (as in so many others) CGI.pm is often the way to go, as its built in functions make on-the-fly html generation in the code a good deal quicker and more readably integrated with the rest of the code. Your example wd become:
use CGI qw/:standard/; print header, start_html, "Today's variable is: ", $myvar, end_html;
+ n.b. that the more complex the html you are outputting, the more time and space the CGI functions become.

When dumping large quantities of info into html tables, I felt the need of something like this, which you may also find useful.

§ George Sherston

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://169731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found