我有员工 CSV 数据,我尝试将每个员工哈希插入到数组中
open($empOutFh,">empOut.txt")
$hash= [];
while(<$empFh>) {
@columnNames = split /,/, $_ if $.==1;
@columnValues = split /,/, $_;
%row = map{$_=>shift @columnValues}@columnNames;
push @$hash,\%row;
}
print Dumper($hash);
我得到的输出有
$VAR1 = [
{
'emp_no' => '11000',
'hire_date
' => '1988-08-20
',
'birth_date' => '1960-09-12',
'gender' => 'M',
'last_name' => 'Bonifati',
'first_name' => 'Alain'
},
$VAR1->[0],
$VAR1->[0],
$VAR1->[0]
]
但是当我尝试打印每一行时,它每次都显示不同的行哈希