Re: Hash of hashes, of hashes, of arrays of hashes
- From: "robic0@xxxxxxxxx" <robic0@xxxxxxxxx>
- Date: 27 Oct 2005 17:27:48 -0700
Tim O'Donovan wrote:
> 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.
I think the structure looks pretty tame here, but its not as simple as
you may think to do this. Its not a simple looping through the
data structures. Its itterative, is usually done with respect to
closures, creating a string for an inner block and substituting that
string for that inner block, which was an array. The next time through,
another block is converted, until finally you have a single string that
is your XML. In the event you would like to do it right, you may want
to check out XML:Simple... gluck!
>
> 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
.
- References:
- Hash of hashes, of hashes, of arrays of hashes
- From: Tim O'Donovan
- Hash of hashes, of hashes, of arrays of hashes
- Prev by Date: Re: if statement
- Next by Date: Re: to parse a string
- Previous by thread: Re: Hash of hashes, of hashes, of arrays of hashes
- Next by thread: Re: Hash of hashes, of hashes, of arrays of hashes
- Index(es):
Relevant Pages
|
|