1

给定这样的哈希值,如何打印我的所有二级哈希键(sig_qtr、日期、范围等):

my $xml = XMLin("./${spec_file}", ForceArray => ['range', 'constant', 'question', 'date', 'sig_yr', 'sig_qtr', 'sig_mth'], KeyAttr => {});

print Dumper $xml->{entities};

打印散列的转储器输出:

$VAR1 = {
          'sig_qtr' => [
                       {
                         'name' => 'q1',
                         'label' => 'q1'
                       },
                       {
                         'name' => 'q4',
                         'label' => 'q4'
                       }
                     ],
          'date' => [
                    {
                      'name' => 'y2_mth',
                      'label' => 'pryr_mth_curr'
                    },
                    {
                      'name' => 'y3_pod6_qtr4',
                      'label' => 'curr_qtd4'
                    }
                  ],
          'range' => [
                       {
                         'name' => 'y0_jun',
                         'end' => '20100631',
                         'start' => '20100601'
                       },
                       {
                         'name' => 'y3_oct',
                         'end' => '20131031',
                         'start' => '20131001'
                       }
                     ],
          'constant' => [
                        {
                          'spec' => '99999999 and 99999999',
                          'name' => 'none_sixmth'
                        }
                      ],
          'sig_yr' => [
                      {
                        'name' => 'y1_sig',
                        'label' => 'ye11'
                      },
                      {
                        'name' => 'y3_sig',
                        'label' => 'ytd'
                      }
                    ],
          'sig_mth' => [
                       {
                         'name' => 'y3_nov',
                         'label' => 'nov12'
                       },
                       {
                         'name' => 'y3_oct',
                         'label' => 'oct13'
                       }
                     ],
          'question' => [
                        {
                          'name' => 'ltrq',
                          'label' => 'q9'
                        },
                        {
                          'name' => 'nextprod',
                          'label' => 'q12a'
                        }
                      ],
          'backfill' => {
                        'label' => 'bf_period'
                      },
          'year' => {
                      'current' => '2013'
                    }
        };

如果将键放入数组中会更好。谢谢。

4

1 回答 1

4
print "$_\n" for keys %{ $xml->entities };

要将它们放入数组中,

my @keys = keys %{ $xml->entities };
于 2013-02-14T16:35:58.677 回答