hi,
I have this snippet:
#!/usr/bin/perl
use strict;
use warnings;
my $ldapserver = "127.0.0.1";
my $basedn = "dc=asenjo,dc=nx";
search("car","mail");
sub search {
use Net::LDAP;
my $ldap = Net::LDAP->new($ldapserver) or die "$0";
# at home I do not need binding, otherwise here bind
my $msg = $ldap->search (base => $basedn,
filter => "(|(cn=*$_[0]*)(uid=*$_[0]*))",
attrs => ["$_[1]",'cn']);
while (my $entry = $msg->shift_entry){
my $attr = $entry->get_value("$_[1]");
my $cn = $entry->get_value("cn");
next unless (defined($entry->get_value("$_[1]")));
print "$cn\t$attr\n";
}
}
and it works a little bit. It does find addresses, but not all of them.
Some objects have several addresses, but this snippet only gets one of
them. Whereas if I try the same but like this:
$msg->code && die $msg->error;
foreach my $entry ($msg->all_entries) {
if ($entry->get_value("$_[1]")) {
print "$_\n" for $entry->get_value( "$_[1]" );
}
}
then it does get all the addresses right. i prefer using a while loop
than a for loop, but if with the while loop it does not work, well, no
problem. I would like to know what I do wrong, though.
--
Groeten,
J.I.Asenjo