dda has asked for the wisdom of the Perl Monks concerning the following question:
What I have is a number of arrays containing LDAP dn`s split by ',' and reversed, as well as corresponding entries:
Each What I need is to create the following hash: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)
Then I will be able to recursively walk trough it.$href->{p=root}{cp=1} = 'entry1' $href->{p=root}{cp=1}{n=1) = 'entry11' #.. etc
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Populating hash keys and LDAP: putting things together
by bart (Canon) on Oct 07, 2003 at 10:46 UTC | |
by dda (Friar) on Oct 07, 2003 at 11:17 UTC | |
by bart (Canon) on Oct 07, 2003 at 11:43 UTC |