Hello, fellow monks!

I have to represent a dependency graph before inserting a new attribute value into an LDAP server. It's actually that objectClasses have a kind of IS-A dependencies... I thought that a hash of hashes of hashes of... could do the trick, but I am having a serious problem.

It's shown in the following code:

# small example my $tree = { top => { inetUser => {}, person => { organizationalPerson => { managedPerson => { personnel => {}, }, }, }, application => { managedApplication => {}, }, }, }; # I need to get the nodes that lead to the one I am looking for sub explore { my $node = shift; my $target = shift; my $stack = shift; # we found it, so we may leave... return $stack if $target eq $stack->[-1]; # we keep looking... my $kids = scalar keys %$node; if ( $kids > 0 ) { for my $key ( keys %$node ) { push @$stack, $key; show( $stack ); explore( $node->{$key}, $target, $stack, $OK ); pop @$stack; } } else { # leaf... no-op } } sub show { print "$_ " for @{$_[0]}; print "\n" } # test my $stack; eval { explore( $tree, 'personnel', [] ); # expected result: "top person organizationalPerson managedPerson +personnel "; }; $stack = $@; show( $stack ); __END__

This works OK, but it's rather an ugly hack... Any way to do this without the exception? thanks!

--
our $Perl6 is Fantastic;


In reply to trees and depth-first search by Excalibor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.