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

Personally, I find your commenting style to be extremely redundant.

I could see more sense in them if you use abbreviated or otherwise possibly confusing variable names, but as they are now your comments just restate the obvious.

The script also feels unecessarily bulky because of the way you declare now and assign later, something many do only if the variable is set in a less-simple fashion (ie, iteratively built, passed through eval).

Taking both of those into consideration, here's how I'd rewrite your script (untested ;)), taking the liberty to roll in some flexibility via Getopt::Long...

#!/usr/bin/perl -w use strict; use Getopt::Long qw/ GetOptions /; # Default variables my %config = ( 'author' => 'me', # Does 'char_set' have to be the same as # 'encoding' in 'page_specs'? 'char_set' => 'iso-8859-1', 'pagetitle' => 'put-your-title-here', # ... ); # Allow user to override any of the %config # defaults by invoking the script with switches # in the form of --variable='new value' GetOptions( \%config, map { "$_=s" } keys %config, ); # Spit out the page print <<XHTML; <?xml version="$config{'xml_version'}" encoding="$config{'encoding'}"?> <!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=$config{'char_set'}" /> <meta name="author" content="$config{'author'}" /> ... XHTML

    --k.


Replies are listed 'Best First'.
Re: Re: Making a 'blank' xhtml page - request for comments
by func (Acolyte) on Apr 15, 2002 at 00:55 UTC

    In regards to the comments and 'declare now, use later' I'm still working out what makes code have clarity and what is unneeded. (I've also just understood what my is used for, apart from being able to stop strict from complaining, so I might do less of that 'declare now, use later' stuff from now on. :) )

    I'm glad you used Getopt::Long as that is something I've wanted to use in this script. You've given me a good head-start. :)

    Thanks