#!/usr/bin/perl my %tree = ( 2 => [3,"HELLO"], HELLO => ["YOU",WORLD], "RAIZ" => [1,2], ); sub show { my ($child , $level) = @_; print " " for 0 .. $level; #fifth spaces of level or anything separator; print "$child \n"; } use Paths::Tree; my $n = Paths::Tree->new(-tree=>\%tree,-sub=>\&show); $n->tree("RAIZ");
Understanding the Tree's filosofy and how to trace it.
Reach for tree's books.
This example show how to generate itself.
(RAIZ) ----> (1) ----> (2) ---->(HELLO)---->(YOU) ---->(WORLD)
This package provides an object class which can be used to get tree paths , with only pure perl code and I don't use other packet or module cpan.
This class generate the paths of a tree from a base node and return in a method , vals in the execution time (tree).
Technically , the tree is composed of childs ans fhathers linked between them.
Tree hash , the component so strings caracter or numbers. example.
Hash is pass how reference hash.
my %tree = ( 2 => [3,"HELLO"], HELLO => ["YOU",WORLD], "RAIZ" => [1,2], ); $obj->{tree} = \%tree;
Origin node what will begin to recursive process tree.
$obj->{origin} = "A";
Receive parameters from object in execution time.
sub params_receive { my ($level , $node) = @_; print " $level , $node \n"; } $obj->{sub} = \¶ms_receive();
This method is the core of object and unique export for use.
Return in execution time two values level and node.
The method is executed and follow is return parameters while recurcive process live.
sub show { my ($child , $level) = @_; print " " for 0 .. $level; #fifth spaces of level or anything separator; print "$child \n"; } use Paths::Tree; my $obj = Paths::Tree->new(-tree=>\%tree,-sub=>\&show,-origin=>"RAIZ"); $obj->tree();
Using the recursive technique in the object methods.
This method is exported as follow: tree()
None by default. But can be exported if it's required.
Please report bugs using: <cristian@codigolibre.cl>.
Powerfull features in the future on object method how for example: find_tree() binary_tree().
AUTHOR Cristian Vasquez Diaz CPAN ID: CAVASQUEZ cristian@codigolibre.cl http://www.codigolibre.cl
COPYRIGHT AND LICENSE
Copyright 2004 by Cristian Vasquez Diaz
This library is free software you can redistribute it and/or modify it under the same terms as Perl itself.
To install Paths::Tree, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Paths::Tree
CPAN shell
perl -MCPAN -e shell install Paths::Tree
For more information on module installation, please visit the detailed CPAN module installation guide.