http://qs321.pair.com?node_id=1169268


in reply to csv to xml

There are some pretty good responses here. I'll add that you do not seem to just be converting CSV to XML. If you were the following would suffice:
my (@data, @hdrs) ; for(<DATA>) { chomp; unless ($first) {@hdrs = split q~,~; $first++; next}; @data = split q~,~; print qq~<record>\n~; for(1,3) {print qq!<$hdrs[$_]> $data[$_] </$hdrs[$_]>\n!}; print qq~</record>\n~; ++$first; } __DATA__ Name,Company,Email,Phone A,X,a.x@aol.com,1111 B,Y,b.y@aol.com,0 C,Z,c.z@aol.com,2222
Produces:
<record> <Company> X </Company> <Phone> 1111 </Phone> </record> <record> <Company> Y </Company> <Phone> 0 </Phone> </record> <record> <Company> Z </Company> <Phone> 2222 </Phone> </record>

What you really appear to be doing is taking some data in one format and embedding it into an XML format. There is a difference between the two. There are actually tools out there to convert XML to other formats of XML as well as tools to format XML for the browser (CSS) that might make what you appear to be doing here moot.

As for the rest of that elaborate output (really everything up to and including the tgroup tag as well as the closing tags) can be added using simple print statements like print qq~<record>\n~;. Or you could use a template module for everything but the dynamic parts of your output.

Celebrate Intellectual Diversity