enikao has asked for the wisdom of the Perl Monks concerning the following question:
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):
We want a flat list of ids and descriptions like this:$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' => [], } ] };
The basic flow is obvious:$descriptions = [ { 'id' => 'xmi.2', 'description' => undef, }, { 'id' => 'xmi.77', 'description' => '', }, { 'id' => 'xmi.75', 'description' => '', }, { 'id' => 'xmi.3', 'description' => '' }, { 'id' => 'xmi.82', 'description' => '', } ];
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retrieving data from deep structure
by kennethk (Abbot) on Dec 05, 2008 at 23:08 UTC | |
by enikao (Initiate) on Dec 05, 2008 at 23:54 UTC | |
by JadeNB (Chaplain) on Dec 06, 2008 at 00:02 UTC | |
by enikao (Initiate) on Dec 06, 2008 at 00:19 UTC | |
|
Re: Retrieving data from deep structure
by planetscape (Chancellor) on Dec 06, 2008 at 06:32 UTC |