Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Your example does not really make a good case for templating. Simple variable substitution is not hard to do without templates. You run into trouble however once you try to dynamically generate tables, lists or such of unpredetermined size. In that case I find that inlining HTML actively promotes bad programming habits. I've seen far too often code where little bits of the output are produced by prints strewn throughout various loops and subroutiness here and there and everywhere. Needless to say one change to the layout that requires tags to be changed in concert between several such parts may require hours of scrambling around. But just a simple change of look isn't even the biggest problem. The real problem with such a style is that you cannot change the alignment of your output without jumping through major hoops. That is, if you had a 2-column vertical output, and you want to change it to a 2-row horizontal output f.ex, you have to change the entire code's logic around to accomodate the new style. UGH. Don't go there. With templates on the other hand, what your code does is collect all the data into a well-defined data structure, and then hands it all over to the templating mechanism. Even if there are major changes to be made to the way the output is produced, your code's logic never needs touching. That's why you should use templates. I find that I now use templates for even the simplest of CGIs if the markup I'm going to produce isn't completely static. ____________Makeshifts last the longest. In reply to Re: OUTPUT: inline or template_based?
by Aristotle
|
|