in reply to Multiple values per attribute from a Net::LDAP query?
note "asref=>1" as get_value() option. This way I get all values for an attribute, like I get multiple objeckClasses for one objectClass attribute. Having the whole ldap structure is nice, but getting the values out of hash is a bit tricky, use Data::Dumper to see the real picture. This is how I get the values from the hash for an attribute:my %href; my ($uid) = @_; $mesg = $ldap->search( # perform a search base => "ou=People,dc=male", filter => "(&(objectClass=posixAccount)(uid=$uid))", ); $mesg->code && die $mesg->error; foreach my $entry ($mesg->entries) { foreach my $attr ($entry->attributes) { $href{"$attr"} = $entry->get_value($attr, asref => 1); } } return \%href
sub getattrval { my ($hashref,$attr) = @_; if ( %$ld{$attr} ) { my $tmp_href = %$ld{$attr}; # return comma delimited string instead of array return join (",",@$tmp_href) if scalar @$tmp_href > 1; return @$tmp_href[0]; } return undef; }
|
|---|