The 'structure' is just a typical object that embeds copies of itself. You typically use recursion to navigate such an object. Such a structure is often called a a tree. If you think about it the file system is a direct parallel with your structure. The properties are analogous to files and the subobjects are analogous to directories. Search CPAN for Tree to see lots of options.

The answer to your aside in literal form is no. If you store a literal value that is what you store. You could store a reference and possibly dig up the info. The question would be why?

The data structure you show could be represented in perl like this (there are other options). Perl can manipulate it. The advantage of embeded objects is that you can recursively call methods on the objects. Data::Dumper Storable FreezeThaw or YAML will all let you serialize it into a stream you can write to disk, read from disk and use to restore your object. I use Storable mostly.

package Object; sub new { bless { _props => {}, _objs => [] }, shift }; sub add_prop { my ( $self, $prop, $value ) = @_; $self->{_props}->{$prop} = $value; } sub add_subobject { my ( $self, @obj ) = @_; push @{$self->{_objs}}, @obj; } my $base = new Object; my $sub1 = new Object; my $sub2 = new Object; my $subsub = new Object; $sub1->add_prop( sub1 => 1 ); $sub2->add_prop( sub2 => 1 ); $subsub->add_prop( deep => 1 ); $sub1->add_subobject( $subsub ); $base->add_prop( foo => 1 ); $base->add_prop( bar => 2 ); $base->add_subobject( $sub1, $sub2 ); use Data::Dumper; print Dumper $base; __DATA__ $VAR1 = bless( { '_objs' => [ bless( { '_objs' => [ bless( { '_objs' = +> [], '_props' +=> { + 'deep' => 1 + } }, 'Object' + ) ], '_props' => { 'sub1' => 1 } }, 'Object' ), bless( { '_objs' => [], '_props' => { 'sub2' => 1 } }, 'Object' ) ], '_props' => { 'foo' => 1, 'bar' => 2 } }, 'Object' );

cheers

tachyon


In reply to Re: MS XAct XAP Data file parsing by tachyon
in thread MS XAct XAP Data file parsing by Ardemus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.