<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Twelve Dozen &#187; perl</title>
	<atom:link href="http://www.twelvedozen.co.uk/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.twelvedozen.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 16 Jun 2010 08:26:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Convert CSV to XML using Perl</title>
		<link>http://www.twelvedozen.co.uk/2009/12/convert-csv-to-xml-using-perl/</link>
		<comments>http://www.twelvedozen.co.uk/2009/12/convert-csv-to-xml-using-perl/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 07:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.twelvedozen.co.uk/2009/12/convert-csv-to-xml-using-perl/</guid>
		<description><![CDATA[In my quest to convert a CSV file to XML I&#8217;ve found the best advice seems to be to use Perl.
Do I have Perl installed on my linux server?
http://www.cyberciti.biz/faq/how-do-i-find-out-what-perl-modules-already-installed-on-my-system/
Enter the following command in shell -
$ instmodsh
To find the version of perl -
http://www.cyberciti.biz/faq/how-can-i-find-out-perl-version/
$ perl -v
Here&#8217;s my findings:
I&#8217;ve been following a tutorial in a book called XML [...]]]></description>
			<content:encoded><![CDATA[<p>In my quest to convert a CSV file to XML I&#8217;ve found the best advice seems to be to use Perl.</p>
<p>Do I have Perl installed on my linux server?<br />
http://www.cyberciti.biz/faq/how-do-i-find-out-what-perl-modules-already-installed-on-my-system/</p>
<p>Enter the following command in shell -<br />
$ instmodsh</p>
<p>To find the version of perl -<br />
http://www.cyberciti.biz/faq/how-can-i-find-out-perl-version/<br />
$ perl -v</p>
<p>Here&#8217;s my findings:</p>
<p>I&#8217;ve been following a tutorial in a book called <a href="http://www.amazon.co.uk/XML-Perl-Mark-Riehl/dp/0735712891/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1262244186&amp;sr=8-2">XML and Perl</a> <span>by Mark Riehl and Ilya Sterin, which is a very good read for a XML and Perl newbie like me.</span></p>
<p><span>Anyway, I&#8217;m using Linux Debian with Perl installed but no other Perl modules. Here&#8217;s what I did:<br />
</span></p>
<p>Installing Perl modules on linux debian</p>
<p>http://www.cyberciti.biz/faq/how-do-i-install-a-perl-module/</p>
<p>perl -MCPAN -e shell</p>
<p>This should display this:</p>
<p>CPAN is the world-wide archive of perl resources. It consists of about<br />
100 sites that all replicate the same contents all around the globe.<br />
Many countries have at least one CPAN site already. The resources<br />
found on CPAN are easily accessible with the CPAN.pm module. If you<br />
want to use CPAN.pm, you have to configure it properly.</p>
<p>If you do not want to enter a dialog now, you can answer &#8216;no&#8217; to this<br />
question and I&#8217;ll try to autoconfigure. (Note: you can revisit this<br />
dialog anytime later by typing &#8216;o conf init&#8217; at the cpan prompt.)</p>
<p>Are you ready for manual configuration? [yes]</p>
<p><strong>Note: This took a long time and lots of files were installed</strong></p>
<p>To install Perl modules:</p>
<p>Here is how you would install XML::SAX using CPAN.pm in the shell mode:<br />
&gt;perl −MCPAN −e shell<br />
CPAN&gt;install XML::SAX</p>
<p>To convert CSV and Excel files to XML you will need to install the modules:</p>
<p>XML::SAXDriver::CSV<br />
XML::SAXDriver::Excel</p>
<p>Issues:</p>
<p>Text::CSV_XS &#8211; This module is required</p>
<p>Unfortunately there was a problem installing the required SAX modules so I needed a new approach. I did manage to install some modules using this method though.</p>
<p>I then found this post http://www.xml.com/pub/a/2001/06/13/perlxml.html</p>
<p>The initial code had a spelling mistake $xsl needs to be $xls</p>
<p>I created a new directory and then created a new Perl file, test.pl</p>
<p><code><br />
use XML::Excel;</code></p>
<p>my $file = &#8216;inventory.xls&#8217;;<br />
my @columns = (&#8217;key&#8217;, &#8216;lname&#8217;, &#8217;size&#8217;, &#8216;form&#8217;);</p>
<p>my $xls = XML::Excel-&gt;new({column_headings =&gt; \@columns});print $file;</p>
<p>$xls-&gt;parse_doc($file);<br />
$xls-&gt;declare_xml({version =&gt; &#8216;1.0&#8242;,<br />
standalone =&gt; &#8216;yes&#8217;});</p>
<p>$xls-&gt;print_xml(&#8217;test.xml&#8217;,<br />
{file_tag    =&gt; &#8216;inventory&#8217;,<br />
parent_tag  =&gt; &#8216;entry&#8217;}<br />
);</p>
<p>Then I uploaded the Excel file inventory.xls to the same directory. Finally I executed the Perl script:</p>
<p># perl test.pl</p>
<p>And it output the XML file test.xml as required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twelvedozen.co.uk/2009/12/convert-csv-to-xml-using-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
