我的结构看起来像这样(散列的散列):
$VAR1 = {
'Lee2000a' => {
'abstract' => 'Abstract goes here',
'author' => 'Lee, Wenke and Stolfo, Salvatore J'
'title' => 'Data mining approaches for intrusion detection'
'year' => '2000'
},
'Forrest1996' => {
'abstract' => 'Abstract goes here',
'author' => 'Forrest, Stephanie and Hofmeyr, Steven A. and Anil, Somayaji'
'title' => 'Computer immunology'
'year' => '1996'
}
};
我想根据三个条件(按此顺序)对该结构进行排序:
第 1 - 根据年份值(1996,2000) 第 2 - 根据“外部”(Lee2000a,Forrest1996)结构键 第 3 - 根据“内部”结构键(摘要、作者、标题、年份)按字母顺序排列。
到目前为止,我有两个代码需要以某种方式组合:
I. 代码符合第 2 条和第 3 条标准
for $i (sort keys(%bibliography)){
print "$i => ", "\n";
for $j (sort keys ($bibliography{"$i"})){
print "\t $j -> ", $bibliography{"$i"}{"$j"},"\n";
}
}
二、代码满足第一个条件
for $i (sort { ($bibliography{$a}->{year} || 0) <=> ($bibliography{$b}->{year} || 0) } keys %bibliography){
print "$i => ", "\n";
for $j (sort keys ($bibliography{"$i"})){
print "\t $j -> ", $bibliography{"$i"}{"$j"},"\n";
}
}
非常感谢你