in reply to List of Children Objects

Howdy!

Untested and (in part) schematic code follows:

sub new { my $class = shift; my $self = { children => [] }; bless $self, $class; } sub addSubBlock # (newblock) { my $self = shift; my $block = shift; push @{$self->{children}}, $block; } sub traverse_preorder { my $self = shift; my @children = (); foreach my $child (@{$self->{children}) { push @children, $child, $child->traverse_preorder; } return @children; }

OK, so I'm using a hash reference for the object data. I'm only using that for ease of illustration.

Updated:renamed traverse_inorder to traverse_preorder. D'oh!

yours,
Michael

Replies are listed 'Best First'.
Re: Re: List of Children Objects
by PhosphoricX (Sexton) on Mar 30, 2004 at 13:17 UTC
    Thanks for your reply, your code was what I was looking for.