Hash of hashes, of hashes, of arrays of hashes



Hi,

I'm trying to create a data structure that will (eventually) make it easier to create a series of slightly different XML documents. The structure will effectively hold a template.

Here's a section of code I am stuck on:


#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my %xmldoc = (
    doc1  => {
        customer => [{name => 'count', format => 'int'},
                     {name => 'unit',  format => 'text'},
        ],
        order    => [{name => 'expected', format => 'date'},
        ],
    },
    #etc
);


The problem I am having is determining how many keys are present in:

$xmldoc{doc1}

and how many elements are present in:

$xmldoc{doc1}{customer}

and so on.

I was then planning on looping through each section and using the data to contruct the XML.

For reference, here is the dumped output of %xmldoc:

$VAR1 = 'doc1';
$VAR2 = {
          'customer' => [
                      {
                        'format' => 'int',
                        'name' => 'count'
                      },
                      {
                        'format' => 'text',
                        'name' => 'unit'
                      }
                    ],
          'order' => [
                       {
                         'format' => 'date',
                         'name' => 'expected'
                       }
                     ]
        };

Any advice would be greatly appreciated.

Thanks.


Kind regards, Tim O'Donovan .



Relevant Pages

  • Re: Hash of hashes, of hashes, of arrays of hashes
    ... > I'm trying to create a data structure that will make it ... > easier to create a series of slightly different XML documents. ... Look up "perldoc -f keys". ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Hash of hashes, of hashes, of arrays of hashes
    ... > I'm trying to create a data structure that will make it ... > easier to create a series of slightly different XML documents. ... > The problem I am having is determining how many keys are present in: ... Xho ...
    (comp.lang.perl.misc)
  • Re: Hash of hashes, of hashes, of arrays of hashes
    ... Tim O'Donovan wrote: ... > I'm trying to create a data structure that will make it ... string for that inner block, ...
    (comp.lang.perl.misc)