I think you are right, there is no good way to always ensure that you never have raw HTML in perl. However use of external stylesheets and external javascript libraries do reduce the amount as do templates.

What I find is that most of my dynamically generated pages consist of is a common header (and sometimes footer) plus a setion where I want to put dynamically generated content. Typically judicious use of Javascript and DHTML means that even navigational bars are in fact common over all pages. As a result the dynamic content is limited to a couple of otherwise empty DIVs which you can then choose how to fill. Thus it is quite possible to have an external html page which conains everything except one or two two blank DIVs like this:

Standard header cruft including <link rel="stylesheet" href="/some/where/sheet.css" type="text/css"> <SCRIPT LANGUAGE="JavaScript" src="/some/where/library.js"></SCRIPT> <BODY> More cruft <DIV id = 'form'> <!-- insert form here --> </DIV> <DIV id = 'results'> <!-- insert results here --> </DIV> </body></html>
Now you need to be strict about what things output stuff to those sections but my scripts typically enforce that by having a print and exit at the bottom which kind of makes it obvious when something started printing halfway up as the page doesn't display right.
# # doing work up above # open (TPLT, "<$tpltfn") or die "Can't open template. $!"; undef $/; # dosn't matter because we're about to quit; $html = <TPLT>; close (TPLT); print header; # add cookies etc if necessary $formidx = index($html,'<!-- insert form here -->'); $residx = index($html,'<!-- insert results here -->'); print substr($html,0,$formidx), create_form($parameters), substr($html,$formidx,($residx-$formidx)), create_results($other_parameters), substr($html,$residx); exit;

Dingus


Enter any 47-digit prime number to continue.

In reply to Re: Meditations On HTML In Perl by dingus
in thread Meditations On HTML In Perl by tadman

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.