Beatnik has asked for the wisdom of the Perl Monks concerning the following question:
package Node; use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{NODES} = []; $self->{TITLE} = undef; bless($self,$class); return $self; } sub title { my $self = shift; if (@_) { $self->{TITLE} = shift; } return $self->{TITLE}; } sub add { my $self = shift; push(@{$self->{NODES}},shift); } sub nodes { my $self = shift; return @{$self->{NODES}}; } 1; # ------- #!/usr/bin/perl -w use strict; use Node; my $parent = Node->new(); $parent->title("Parent"); my $child1 = Node->new(); $child1->title("Child 1"); $parent->add($child1); my $child2 = Node->new(); $child2->title("Child 2"); $parent->add($child2); foreach my $ref ($parent->nodes) { print $ref->title; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building an object tree
by unixwzrd (Beadle) on Feb 26, 2001 at 02:10 UTC | |
by tilly (Archbishop) on Feb 26, 2001 at 02:19 UTC | |
by MeowChow (Vicar) on Feb 26, 2001 at 03:59 UTC | |
by tilly (Archbishop) on Feb 26, 2001 at 05:25 UTC | |
by Beatnik (Parson) on Feb 26, 2001 at 02:19 UTC | |
|
Re: Building an object tree
by mirod (Canon) on Feb 26, 2001 at 13:41 UTC |