Recently I've asked two questions: Traverse LDAP Tree and Populating hash keys. The first one wasn't actually answered, and I decided to apply second way. It's too bad for me, but I can't understand how to implement the following task using techniques described in Populating hash keys.

What I have is a number of arrays containing LDAP dn`s split by ',' and reversed, as well as corresponding entries:

qw(p=root cp=1) qw(p=root cp=1 n=1) qw(p=root cp=1 n=1 n=1) qw(p=root cp=1 n=1 n=1 n=1) qw(p=root cp=1 n=1 n=1 n=1 n=1) qw(p=root cp=1 n=1 n=1 n=1 n=2) qw(p=root cp=1 n=1 n=1 n=1 n=3) qw(p=root cp=1 n=1 n=1 n=2) qw(p=root cp=1 n=1 n=1 n=2 n=1) qw(p=root cp=1 n=1 n=1 n=2 n=2) qw(p=root cp=1 n=1 n=1 n=2 n=3)
Each What I need is to create the following hash:
$href->{p=root}{cp=1} = 'entry1' $href->{p=root}{cp=1}{n=1) = 'entry11' #.. etc
Then I will be able to recursively walk trough it.

My code:

use strict; use Net::LDAP; use Text::ParseWords; use Data::Dumper; my $host = 'somehost'; my $port = 400; my $user = 'p=xxx'; my $pass = 'secret'; my $base = 'cp=1, p=root'; my $ldap = Net::LDAP->new($host, port => $port) or die "$@\n"; $ldap->bind($user, password => $pass); my $mesg = $ldap->search ( base => "$base", filter => "(objectClass=*)", ); $mesg->code && die $mesg->error . "\n"; my %entries; foreach my $entry ($mesg->all_entries) { my $dn = $entry->dn; $dn =~ s/\s+//g; $entry->dn($dn); my @path = reverse parse_line(",", 1, $dn); $entries{join ',', @path} = $entry; # this is not what I want exa +ctly } $ldap->unbind; foreach my $dn (sort keys %entries) { print "$dn\n"; } exit;

--dda


In reply to Populating hash keys and LDAP: putting things together by dda

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.