关于迭代哈希数组的大量线程,我每天都这样做.但是现在我想迭代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'
},
Run Code Online (Sandbox Code Playgroud)
从理论上讲,这是我想要的.
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
Run Code Online (Sandbox Code Playgroud)
use warnings;
use strict;
foreach my $criterion (@$criteria) {
foreach my $chapter (@{$criterion->{chapters}}) {
print $chapter->{title}, "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
150 次 |
| 最近记录: |