哈希值的動態數組我有一個CSV文件中像這樣:在Perl
name,email,salary
a,[email protected],1000
d,[email protected],2000
現在,我需要這種轉換在Perl哈希映射的陣列,所以當我做這樣的事情:
table[1]{"email"}
我寫的代碼是:
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);
但我沒有得到期望的結果.. u能幫助?在此先感謝...
使用'文字:: CSV'解析一個CSV文件。 – chepner 2013-03-25 13:47:47