很多关于迭代哈希数组的线程,我每天都会这样做。但是现在我想在 AoH 和 AoH 中迭代。我对数组“章节”感兴趣,因为我想为该内部数组的每个数组元素添加一个哈希:
$criteria = [
{
'title' => 'Focus on Learning',
'chapters' => [
{
'content_id' => '182',
'criteria_id' => '1',
'title' => 'Focus on Learning',
},
{
'content_id' => '185',
'criteria_id' => '1',
'title' => 'Teachers Role',
},
{
'content_id' => '184',
'criteria_id' => '1',
'title' => 'Parents in Class',
},
{
'content_id' => '183',
'criteria_id' => '1',
'title' => 'Students at Home',
}
],
'tot_chaps' => '4'
},
从理论上讲,这是我想做的事情。
for my $i ( 0 .. $#$criteria ) {
for my $j ( 0 .. $#$criteria->[$i]{'chapters'}) {
print $criteria->[$i]{'chapters'}->[$j]{'title'}."\n";
}
}
print $criteria->[$i]{'chapters'}->[1]{'title'}."\n"; -> Teachers Role