in reply to Making a 'blank' xhtml page - request for comments

func sez :
I would appreciate your comments/criticism on the script.
sub page_body { # The body area and closing tag print <<XHTMLBODY; <body> </body> </html> }
this doesn't even compile, but that's probably a bad copy & paste problem -- you forgot the end XHTMLBODY.
Once that's fixed, we get the following output :
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; chartset=iso-8859-1" /> <meta name="author" content="mynamehere" /> <meta name="copyright" content="mynamehere" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <title>PUT-YOUR-TITLE-HERE</title> </head> <body> </body> </html>
Not bad. It's valid XHTML, and it doesn't look too bad. You've accomplished what you set out to do.

However, through the use of CGI, this code can be compacted :
use CGI::Fast qw(start_html endhtml); print start_html(-title=>'PUT-YOUR-TITLE-HERE', -enctype=>'iso-8859-1', -meta=>{ 'author'=>'my name here', 'copyright'=>'my name here', 'keywords' => '', 'description' =>'' }, ), end_html ;
which outputs
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>P +UT-YOUR-TI TLE-HERE</title> <meta name="description" content="" /> <meta name="author" content="my name here" /> <meta name="keywords" content="" /> <meta name="copyright" content="my name here" /> </head><body http-equiv="text/html" enctype="iso-8859-1"></body></html +>
Pretty similar (the encoding in the xml header differs and the DTD is XHTML Basic, not Strict, and CGI adds the http-equiv and enctype to the body tag.). If this isn't too big a difference, you could cut down your code to far fewer lines. If you're concerned about readability, substitue CGI::Pretty for CGI::Fast. (Wouldn't a CGI::Fast::Pretty be nice?)

Replies are listed 'Best First'.
Re: the finest hand rolled XHTML known to man vs. evil factory produced XHTML (boo)
by func (Acolyte) on Apr 15, 2002 at 00:31 UTC
    this doesn't even compile, but that's probably a bad copy & paste problem -- you forgot the end XHTMLBODY.

    *cough* yes. Sometimes, me, my browser and editor don't get on. :) :)

    Your code with CGI::Fast certainly is smaller, and I like the fact you only have to write out the variable information.

    I'll be trying out CGI::Pretty as I like all that indented stuff and I can pretend to everyone I'm still a html hand-roller. :)

    Thanks.