in reply to Re: Retrieving data from deep structure
in thread Retrieving data from deep structure

kennethk, thank you very much! A little more tweaking, at now it works. I'm posting the final function (just for reference for others seeking like me):
sub get_descriptions { my ($self, $packages) = @_; my @descriptions = (); for my $class (@{$packages->{classes}}) { my %local_hash = (); $local_hash{id} = $class->{classid}; $local_hash{description} = $class->{classdescription}; push @descriptions, {%local_hash}; for my $method (@{$class->{methods}}) { my %local_hash = (); $local_hash{id} = $method->{methodid}; $local_hash{description} = $method->{methoddescription} +; push @descriptions, {%local_hash}; } for my $attribute (@{$class->{attributes}}) { my %local_hash = (); $local_hash{id} = $attribute->{attributeid}; $local_hash{description} = $attribute->{attributedescri +ption}; push @descriptions, {%local_hash}; } } @descriptions; }

For your note: I agree for the example the arrays are not neccessary, but there can be multiple methods or attributes (it's an UML XMI generator). As far as I understood the code, there are no accessor methods (the already existing part of the generator retrieves its data in the same way).

Thank you again, this helps me a lot!

Niko

PS: Is there a good reference where I can learn the subtleties of scalars, arrays and hashes? I understand the basic difference, but I'm totally at a loss when to use which prefix (e. g. my %local_hash = (); vs. $local_hash{id} vs. $class->{methods}).

Replies are listed 'Best First'.
Re^3: Retrieving data from deep structure
by JadeNB (Chaplain) on Dec 06, 2008 at 00:02 UTC
    PS: Is there a good reference where I can learn the subtleties of scalars, arrays and hashes? I understand the basic difference, but I'm totally at a loss when to use which prefix (e. g. my %local_hash = (); vs. $local_hash{id} vs. $class->{methods}).
    perldata; and, for the fancy stuff, perldsc.

      Thanks again! This site (and its members) is very helpful.

      Niko