in reply to outputting xml

Just as it is a bad idea to parse HTML with home-brewn regexes, for anything but the most trivial XML-files, don't even think of writing such files by simply print-ing them. It is far too easy to get it wrong in thousand subtle ways.

Modules such as XML::Writer or XML::ValidWriter are a much better bet. It is not for nothing that XML-files have a DOCTYPE which can be used to check the validity of the file. XML::ValidWriter uses the DOCTYPE to make sure it writes a valid XML-file.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James