Arrays 如何在Perl中编写复杂的哈希数组?
有一项任务让我困惑了好一阵子: 我们定期以.csv文件的形式获取学生的考试结果。标题包含一些元数据,例如ID、性别、出生日期、状态、考试室、座位号、考试版本以及60个问题的分数(如果答案错误、半正确或正确,则为0.0 0.5 1.0分)。考试共有6个版本(A-F),不同的只是60道题的顺序。该信息存储用于统计评估,该评估需要根据考试大纲进行正确对齐(a-F版为7列的.txt文件,第7列为正确答案)。 我尝试将.csv文件作为一个散列数组来容纳,以生成一个不同的.csv或tabbed.txt文件,其中所有考试结果都以统一的顺序显示,以便以后进行统计评估 例如: 标题-- 身份证,性别,生日,订单,房间,座位,版本,分数 277710814533,f,1993年2月1日,m,sr_3,A11,A,1,1,1,1,1,1,5,1,1,1,0,1,1,5,1,1,1,1,0,1,1,5,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,0,1,1,1,1,1,1,1,1,1,1,1,1 755310765962,f,31/07/1992 00:00,v,aula,C11,C,1,5,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,5,1,0,1,0,1,1,1,1,1,1,1,5,0,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,5,5,1,1,1,5,1,1,5,1,1,1,1,5,1,1,1,1,5 394610513538,m,20/10/1992 00:00,m,sr_3,E13,E,1,1,0,5,1,1,1,1,1,1,5,1,1,1,1,5,1,1,1,5,1,1,1,1,1,5,1,1,1,1,0,5,5,0,0,0,1,1,1,1,1,5,0,5,0,5,0,0,5,1,1,1,1,1,0,5,1,5,5,5,1,0,5,5,1,1,1,0,5,5,1,1,5,5,1,5,5,5,5,1,1,1,5,5,1, 代码根据以下方案生成哈希键:Arrays 如何在Perl中编写复杂的哈希数组?,arrays,csv,hash,perl-data-structures,Arrays,Csv,Hash,Perl Data Structures,有一项任务让我困惑了好一阵子: 我们定期以.csv文件的形式获取学生的考试结果。标题包含一些元数据,例如ID、性别、出生日期、状态、考试室、座位号、考试版本以及60个问题的分数(如果答案错误、半正确或正确,则为0.0 0.5 1.0分)。考试共有6个版本(A-F),不同的只是60道题的顺序。该信息存储用于统计评估,该评估需要根据考试大纲进行正确对齐(a-F版为7列的.txt文件,第7列为正确答案)。 我尝试将.csv文件作为一个散列数组来容纳,以生成一个不同的.csv或tabbed.txt文件,
while ( <FH> ) {
chomp ;
if ( /^\d\d\d/) {
( $id , $gender , $birthday , $status , $room , $seat , $version , @points ) = split ( /,/ , $_ ) ;
$student = {
'id' => $id ,
'gender' => $gender ,
'birthday' => $birthday ,
'position' => $position ,
'room' => $room ,
'seat' => $seat ,
'version' => $version ,
'points' => @points
} ;
push ( @candidates , $student ) ;
}
} ;
close FH ;
print "Number of candidates processed: " . ( $#candidates + 1 ) . "\n" ;
有什么线索吗
Thx-Harald-使用\@点@点在哈希构造函数中展开以生成: “点数”=>$Points[0],$Points[1]=>$Points[2]
755310765962
$VAR1 = \{
'0' => '0',
'gender' => 'f',
'id' => '755310765962',
'points' => '1',
'room' => 'aula',
'.5' => undef,
'1' => '.5',
'birthday' => '31/07/1992',
'seat' => 'A11',
'version' => 'A',
'status' => 'v'
};