Hi,

I'm experienced in several programming languages, but Perl beats me /-: So I ask you people wiser than me for help.

I want to amend a Perl program (JSDoc) with new functionality. The basic task is simple: We have a deep structure and want to retrieve specific items, putting them into a new structure. The source structure looks like this (I stripped everything not relevant):

$VAR1 = { 'classes' => [ { 'classid' => 'xmi.2', 'classdescription' => undef, 'methods' => [ { 'methoddescription' => '', 'methodid' => 'xmi.77', } ], 'attributes' => [ { 'attributedescription' => '', 'attributeid' => 'xmi.75', } ], }, { 'classid' => 'xmi.3', 'classdescription' => '', 'methods' => [ { 'methoddescription' => '', 'methodid' => 'xmi.82', } ], 'attributes' => [], } ] };
We want a flat list of ids and descriptions like this:
$descriptions = [ { 'id' => 'xmi.2', 'description' => undef, }, { 'id' => 'xmi.77', 'description' => '', }, { 'id' => 'xmi.75', 'description' => '', }, { 'id' => 'xmi.3', 'description' => '' }, { 'id' => 'xmi.82', 'description' => '', } ];
The basic flow is obvious:
FOREACH class PUT classid, classdescription INTO descriptions FOREACH method PUT methodid, methoddescription INTO descriptions END FOREACH FOREACH attribute PUT attributeid, attributedescription INTO descriptions END FOREACH END FOREACH

I've tried this for several hours now, but I got mixed up in arrays, hashes, pseudo-hashes, etc.

Any hints are greatly appreciated.

Niko

In reply to Retrieving data from deep structure by enikao

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.