次のマルチレベル ハッシュ リファレンスを反復処理し、親子関係を示す単一の選択ボックスを作成します。次は、ダンパーから取得したハッシュ リファレンスです。SO 基本的に、HTML 選択ボックスを構築できるサブルーチンを作成したいと考えています。
my $hash = {
'136666' => {
'children' => {
'136954' => {
'children' => {
'137004' => {
'title' => 'child of child',
'parentid' => '136954'
}
},
'title' => 'add child',
'parentid' => '136666'
}
},
'title' => 'Main Forum',
'parentid' => '-1'
},
'136720' => {
'children' => {
'136997' => {
'title' => 'under category',
'parentid' => '136720'
}
},
'title' => 'Android',
'parentid' => '-1'
},
'136719' => {
'title' => 'Nokia C2-01',
'parentid' => '-1'
},
'136665' => {
'children' => {
'136994' => {
'title' => 'sub form under test forum',
'parentid' => '136665'
}
},
'title' => 'test',
'parentid' => '-1'
}
};
次のようなボックスを選択したい:
<option value='136666'>Main Forum</option>
<option value='136954'>--add child</option>
<option value='137004'>----child of child'</option>
<option value='136665'>test</option>
<option value='136994'>--sub form under test forum</option>
<option value='136719'>Nokia C2-01</option>
<option value='136720'>--Android</option>
<option value='136997'>----under category'</option>
前もって感謝します!
新しいハッシュは次のとおりです。
my $hash = {
'4' => {
'forumid' => '136720',
'children' => {
'7' => {
'forumid' => '136997',
'title' => 'under category',
'is_category' => '0',
'parentid' => '136720'
}
},
'title' => 'Android',
'is_category' => '0',
'parentid' => '-1'
},
'1' => {
'forumid' => '136666',
'children' => {
'5' => {
'forumid' => '136954',
'children' => {
'8' => {
'forumid' => '137004',
'title' => 'child of child',
'is_category' => '0',
'parentid' => '136954'
}
},
'title' => 'add child',
'is_category' => '0',
'parentid' => '136666'
}
},
'title' => 'Main Forum',
'is_category' => '0',
'parentid' => '-1'
},
'3' => {
'forumid' => '136719',
'title' => 'Nokia C2-01',
'is_category' => '1',
'parentid' => '-1'
},
'2' => {
'forumid' => '136665',
'children' => {
'6' => {
'forumid' => '136994',
'children' => {
'9' => {
'forumid' => '137012',
'title' => 'another child',
'is_category' => '0',
'parentid' => '136994'
}
},
'title' => 'sub form under test forum',
'is_category' => '0',
'parentid' => '136665'
}
},
'title' => 'test',
'is_category' => '0',
'parentid' => '-1'
}
};
次のように出力が必要です
<div id='136666'>Main Forum
<div>
<a href='136954'>add child</a>, <a href='137004'>child of child</a>
</div>
</div>
<div id='136665'>test
<div>
<a href='136994'>sub form under test forum</a>, <a href='137012'>another child</a>
</div>
</div>
<div id='136719'>Nokia C2-01
<div id='136720'>Android
<div>
<a href='136997'>under category</a>
</div>
</div>
</div>
以下のようになります。
Main Forum
add child, child of child
test
sub form under test forum, another child
Nokia C2-01
Android
under category
前もって感謝します。