How does this look like for an update?
package Isanchez; use strict; use Carp; our $VERSION = '0.01'; sub new { my ($class, $file) = @_; my $self = bless {}, $class; $self->_build($file); return $self; } sub _build { my ($self, $file) = @_; croak "Unable to retrieve data" unless open(INPUT,$file); while (my $line = <INPUT>) { chomp $line; my($id, $parent_id, $title) = split /\s+/ , $line, 3; unless ($title && $id =~ /^\d+$/ && $parent_id =~ /^\d+/ && $p +arent_id < $id) { carp "Unable to parse\n$line"; next; } $self->{$title}{decendent} = $id; push @{$self->{decendents}{$parent_id}}, $title; } } sub get_decendents { my ($self, $origin) = @_; croak "You must enter an origin in the tree" unless $origin; croak "$origin can not be found" unless exists $self->{$origin}; my $index = $self->{$origin}{decendent}; my @list = @{$self->{decendents}{$index}} if exists $self->{decend +ents}{$index}; return $origin unless @list; my @decendents = ($origin); while (@list) { my $decendent = shift @list; push @decendents, $decendent; my $index = $self->{$decendent}{decendent}; push @list, @{$self->{decendents}{$index}} if exists $self->{d +ecendents}{$index}; } return @decendents; }
Cheers - L~R
In reply to Re: Re: Code Review (recursive data structure)
by Limbic~Region
in thread Code Review (recursive data structure)
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |