Re: Hash of hashes, of hashes, of arrays of hashes




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

.



Relevant Pages

  • 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. ... I was then planning on looping through each section and using the data to contruct the XML. ... Tim O'Donovan. ...
    (comp.lang.perl.misc)
  • Re: Writing a Text Editor in Lisp
    ... It is hard to say which is the "best" data structure without knowing ... changed) a gap buffer to hold the entire text of the buffer. ... Multics Emacs used a doubly linked list of strings, ... editing operations on different lines, ...
    (comp.lang.lisp)
  • Re: Alternative to System.runFinalizersOnExit()?
    ... failure to allocate a 2KB buffer in ... the BufferedInputStream constructor is going to be an example of the ... outputting a baroque data structure to render. ... read it into a huge String. ...
    (comp.lang.java.programmer)
  • request for advice - possible ElementTree nexus
    ... I have inherited some python code that accepts a string object, ... contents of which is an XML document, ... changes I make must continue to produce the same data structure that is ... ElementTree handles parsing XML documents ...
    (comp.lang.python)
  • Re: Increasing efficiency in C
    ... > You don't know where the pointer will end pointing to. ... > representation of a C string. ... Wow Dan, ... My whole point is that data structure development should ...
    (comp.lang.c)