Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Meditations On HTML In Perl

by dingus (Friar)
on Dec 04, 2002 at 13:24 UTC ( [id://217469]=note: print w/replies, xml ) Need Help??


in reply to Meditations On HTML In Perl

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found