我有一个哈希,它有一个键'form'和Table
的多个键指向其他哈希。但是,表格的任意数量为tr
,tr
将包含任意数量的td
。所以问题是它有匿名数组。如何从这个哈希打印一个表?
'form'=>{
'Table2' => {
'tr' => [
{
'td' => [
{
'db_feild_name' => 'project_details',
'type' => 'texta',
'display_name' => 'Project Detail',
'mandate' => '1'
},
{
'db_feild_name' => 'project_name',
'type' => 'text',
'display_name' => 'Project Name',
'mandate' => '1'
},
{
'db_feild_name' => 'project_date',
'type' => 'date',
'display_name' => 'Date'
}
]
},
{
'td' => [
{
'db_feild_name' => 'issue_name',
'type' => 'text',
'display_name' => 'Name',
'mandate' => '1'
},
{
'db_feild_name' => 'last_name',
'type' => 'text',
'display_name' => 'last Name',
'mandate' => '1'
},
{
'db_feild_name' => 'age',
'type' => 'text',
'display_name' => 'Age'
}
]
}
],
'Table_Header' => 'test_table2',
'Title' => 'i am table'
}
}
答案 0 :(得分:0)
说明:
$table
指向,
{
'tr' => [..],
'Table_Header' => 'test_table2',
'Title' => 'i am table'
}
$tr
指向,
{
'td' => [..]
},
和$td
指向
{
'db_feild_name' => 'project_details',
'type' => 'texta',
'display_name' => 'Project Detail',
'mandate' => '1'
},
假设您的哈希为%h
for my $table (values %{ $h{"form"} }) {
# print <table>
print $table->{"Table_Header"}, $table->{"Title"};
for my $tr (@{ $table->{"tr"} }) {
# print <tr>
for my $td (values %$tr) {
# print <td>
print $td->{"db_feild_name"}; # type,display_name,etc
# print </td>
}
# print </tr>
}
# print </table>
}