Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Introduction to Tree::DAG_Node

by gmax (Abbot)
on Mar 21, 2002 at 07:13 UTC ( #153259=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
                 +-------+--------+----------+
                 | order | insert | retrieve |
    ...
    |binary tree | yes   | fast   | fast     |
    |DAG tree    | yes   | fast   | slow     |
    +------------+-------+--------+----------+
    
  2. or download this
                   company
                 /    |   \
    ...
            /  \     / \
         net  store |   |
              research development
    
  3. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
    
    my $pm = Tree::DAG_Node->new;
    $pm->name('PerlMonks');
    
  4. or download this
    my $tutorials = Tree::DAG_Node->new;
    $tutorials->name('tutorials');
    ...
    $tutorials->new_daughter->name('syntax');
    $tutorials->new_daughter->name('references');
    $tutorials->new_daughter->name('data');
    
  5. or download this
    $pm->add_daughter($tutorials);
    
  6. or download this
    my $reviews = Tree::DAG_Node->new;
    
    ...
    my $SOPW = Tree::DAG_Node->new;
    $SOPW->name('SOPW');
    $pm->add_daughter($reviews, $SOPW); 
    
  7. or download this
    print map "$_\n", @{$pm->draw_ascii_tree};
    
  8. or download this
    $pm->new_daughter->name('Meditations');
    
  9. or download this
    print $pm->dump_names;
    
  10. or download this
                                  |
                             <PerlMonks>
    ...
        'modules'
      'SOPW'
      'Meditations'
    
  11. or download this
    $pm->walk_down({
        callback => sub {
    ...
        _depth => 0,
        treename => 'PerlMonks' 
    });
    
  12. or download this
    (*) PerlMonks
      tutorials
    ...
        modules
      SOPW
      Meditations
    
  13. or download this
        basics
        syntax
    ...
      SOPW
      Meditations
    (*) PerlMonks
    
  14. or download this
    sub traverse {
        my $node = shift;
    ...
    ....modules 0:1:1
    ..SOPW 0:2
    ..Meditations 0:3
    
  15. or download this
    $pm->attributes (['The', ['best', 'Perl'],['site']]);
    $tutorials->attributes ({
    ...
    $pm->walk_down({callback=>sub{
       print $_[0]->name," ", ref $_[0]->attributes,"\n"; 
    }});
    
  16. or download this
                               |                           
                             <root>                         
    ...
     /---\   /---\         /---+---\                         
     |   |   |   |         |   |   |                         
    <i> <j> <k> <l>       <5> <6> <7>                        
    
  17. or download this
    my @daughters = $root->daughters; # <a> and <b>
    my @b_daughthers = $daughters[1]->daughters; # <b>'s daughters
    ...
    my @right = $third->right_sisters; # <s>, <t> <u>
    my $mama = $third->mother; # <b>
    my @ancestors = $third->ancestors; # <b> <root>
    
  18. or download this
    my @descnames = map {$_->name} $node1->descendants;
    # @descnames = qw(w i j x k l);
    
  19. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
        $self->attributes($options);
        return $self;
    }
    
  20. or download this
    sub employees {
        my $node = shift;
    ...
            1}});
        return wantarray? @found : @found ? $found[0] : undef;
    }
    
  21. or download this
    sub clear_totals {
        $_[0]->walk_down({ callback => sub {
    ...
                $node->budget
        }, _depth => 0 });
    }
    
  22. or download this
    package main;
    
    ...
    $company->sum_up;
    $company->print_wealth;
    print map "$_\n", @{$company->draw_ascii_tree};
    
  23. or download this
    company empl: 43  budget:   290000
      sales empl: 14  budget:    90000
    ...
      R&D   empl: 25  budget:   190000
        res empl: 10  budget:   100000
        dev empl: 15  budget:    90000
    
  24. or download this
                  |
              <company>
    ...
      /-----\            /-----\
      |     |            |     |
    <net> <str>        <res> <dev>
    
  25. or download this
    my $node = $root->address('0:2:1');
    
  26. or download this
    my $node = $root->address('0:2:1');
    $node->mother->new_daughter_left; 
    # now $node's address is '0:2:2'
    
  27. or download this
    sub by_attribute {
        my ($self, $key, $id) = @_;
    ...
            1}});
        return $found;
    }
    
  28. or download this
    my $node = $root->by_attribute( 'ID', 'nutcracker');
    
  29. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
        }
    }
    print map "$_\n", @{$root->draw_ascii_tree};
    
  30. or download this
                     |                 
                  <root>               
    ...
     /---+---\   /---+---\   /---+---\ 
     |   |   |   |   |   |   |   |   | 
    <a> <b> <c> <d> <e> <f> <g> <h> <i>
    
  31. or download this
    my $node = $root->address('0:1');
    $node->replace_with_daughters;
    print map "$_\n", @{$root->draw_ascii_tree};
    
  32. or download this
                     |
                  <root>               
    ...
     /---+---\               /---+---\ 
     |   |   |               |   |   | 
    <a> <b> <c>             <g> <h> <i>
    
  33. or download this
    $node = $root->address('0:4');
    my $dest = $root->address('0:2');
    $dest->add_daughter($node);
    print map "$_\n", @{$root->draw_ascii_tree};
    
  34. or download this
                   |               
                <root>             
    ...
    <a> <b> <c>      /---+---\     
                     |   |   |     
                    <g> <h> <i>    
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://153259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2015-07-30 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls