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


In reply to Re: csv to xml by InfiniteSilence
in thread csv to xml by vavz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.