1

我有哈希,它将有一个键“表单”和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'
    }
}
4

1 回答 1

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>
}
于 2013-05-11T09:57:15.170 回答