我在使用Perl将以下csv代码片段转换为哈希值时遇到了问题。将csv转换为阵列的perl哈希值
emp_no,birth_date,first_name,last_name,gender,hire_date
10001,1953-09-02,Georgi,Facello,M,1986-06-26
10002,1964-06-02,Bezalel,Simmel,F,1985-11-21
10003,1959-12-03,Parto,Bamford,M,1986-08-28
10004,1954-05-01,Chirstian,Koblick,M,1986-12-01
10005,1955-01-21,Kyoichi,Maliniak,M,1989-09-12
哈希应该是这样的:
$employee = {
emp_no=>[10001,10002,10003,10004,10005],
birth_date=>[1953-09-02,1964-06-02,1959-12-03],
simarly for fistname , lastname and hire_date
}
我已经试过这样
while(<FH>){
@keys = split /,/,$_ if $.==1; #for the first line
@row = split /,/,$_;
push @hash{@keys},@row;
}
什么是你的问题?如果您无法使脚本正常工作,请显示您尝试过的内容。 – Barmar
将它转换为散列数组而不是散列数组不是更好吗? – Barmar
请参阅http://search.cpan.org/~makamaka/Text-CSV-1.32/lib/Text/CSV.pm了解处理CSV文件的包。 – Barmar