<?xml version="1.0" encoding="windows-1252"?>
<node id="971228" title="Read data from csv file to a data structure format" created="2012-05-18 02:59:20" updated="2012-05-18 02:59:20">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
Hi Perlmonks,&lt;br&gt;
I would like to create a data structure from a csv file. &lt;p&gt;

The sample csv file as follows&lt;br&gt;
&lt;code&gt;
Product Name,Product Code,Company1,Company2,Company3
Test One,C001,Y,N,N
Test Two,C002,N,N,Y
Test Three,C003,Y,Y,N
&lt;/code&gt;
&lt;br&gt;
and I am looking for an output in the below format
&lt;br&gt;
&lt;code&gt;
{ 
Company1 =&gt; {C001 =&gt; Y, C002 =&gt; N, C003 =&gt; Y}, 
Company2 =&gt; {C001 =&gt; N, C002 =&gt; N, C003 =&gt; Y}, 
Company3 =&gt; {C001 =&gt; Y, C002 =&gt; Y, C003 =&gt; N}
}

&lt;/code&gt;
&lt;br&gt;
I tried using Text::CSV_XS module, but not able form a structure as mentioned above
&lt;br&gt;
&lt;code&gt;
use Text::CSV_XS;
my $csv = Text::CSV_XS-&gt;new();
open my $FH, "&lt;", "test.csv";
while (&lt;$FH&gt;) {
$csv-&gt;parse($_);
my @fields = $csv-&gt;fields;

&lt;/code&gt;
Is there any CPAN module available to get this structure&lt;br&gt;
Can you please help on this.&lt;br&gt;

Thanks&lt;br&gt;</field>
<field name="reputation">
12</field>
</data>
</node>
