I have a CSV file like this:
name,email,salary
a,b@b.com,1000
d,e@e.com,2000
Now, I need to transform this to an array of hash-maps in Perl, so when I do something like:
table[1]{"email"}
it returns e@e.com.
The code I wrote is :
open(DATA, "<$file") or die "Cannot open the file\n";
my @table;
#fetch header line
$line = <DATA>;
my @header = split(',',$line);
#fetch data tuples
while($line = <DATA>)
{
my %map;
my @row = split(',',$line);
for($index = 0; $index <= $#header; $index++)
{
$map{"$header[$index]"} = $row[$index];
}
push(@table, %map);
}
close(DATA);
But I am not getting desired results.. Can u help?? Thanks in advance...