in reply to trees and depth-first search
my $tree = { top => { inetUser => {}, person => { organizationalPerson => { managedPerson => { personnel => {}, }, }, }, application => { managedApplication => {}, }, }, }; sub explore { my $node = shift; my $target = shift; my $stack = shift; if( $target eq $stack->[$#stack]) { show( $stack ); exit 0; } my $kids = scalar keys %$node; if ( $kids > 0 ) { for my $key ( keys %$node ) { push @$stack, $key; explore( $node->{$key}, $target, $stack, $OK ); pop @$stack; } } } sub show { print "$_ " for @{$_[0]}; print "\n" } my $stack; explore( $tree, 'personnel', []);
insaniac][r0nin: ~/work/code/perl : perl tree_ldap.pl top person organizationalPerson managedPerson personnel
Update: also removed the eval ;-)
|
|---|