Within this hash, attribute values are always an array, i.e. single valued attributes are returned in an array containing a single value. ... this would require to know, which attribute is single valued and which is multivalued. Is there a way to figure this out?

I'm not an LDAP expert, but are you referring to attributes like objectclass in the following example? Going with that assumption, in this example, the way to check is to de-reference the array reference with @{...} (perlreftut and perlref), and use the array in scalar context to get the number of elements it contains, e.g. if ( @array > 1 ) { print "More than one element in the array.\n" }. You can walk the data structure as returned by as_struct, or, probably better, you can walk the Net::LDAP::Entry objects returned by Net::LDAP::Search. I've shown examples of both in the following.

use warnings; use strict; use Data::Dump; use Net::LDAP; my $ldap = Net::LDAP->new('ldap.forumsys.com') or die "$@"; my $mesg = $ldap->bind( 'cn=read-only-admin,dc=example,dc=com', password => 'password' ); $mesg->code and die $mesg->error; my $srch = $ldap->search( base => "dc=example,dc=com", filter => "(uid=test)" ); $srch->code and die $srch->error; # walk with perl my $struct = $srch->as_struct; dd $struct; for my $entryname (sort keys %$struct) { my $entry = $struct->{$entryname}; for my $attr (sort keys %$entry) { print "$attr is ", @{$entry->{$attr}}>1 ? "multi" : "single", "-valued\n"; } } print "---\n"; # walk with Net::LDAP for my $entry ($srch->entries) { for my $attr ( $entry->attributes ) { my @values = $entry->get_value($attr); print "$attr is ", @values>1 ?"multi" : "single","-valued\n"; } } $mesg = $ldap->unbind; $mesg->code and die $mesg->error; __END__ { "uid=test,dc=example,dc=com" => { cn => ["Test"], displayname => ["Test"], gidnumber => [0], givenname => ["Test"], homedirectory => ["home"], initials => ["TS"], o => ["Company"], objectclass => ["posixAccount", "top", "inetOrgPerson"], sn => ["Test"], uid => ["test"], uidnumber => [24601], }, } cn is single-valued displayname is single-valued gidnumber is single-valued givenname is single-valued homedirectory is single-valued initials is single-valued o is single-valued objectclass is multi-valued sn is single-valued uid is single-valued uidnumber is single-valued --- objectClass is multi-valued gidNumber is single-valued givenName is single-valued sn is single-valued displayName is single-valued uid is single-valued initials is single-valued homeDirectory is single-valued cn is single-valued uidNumber is single-valued o is single-valued

In reply to Re: net::ldap ->singel valued attributes and multivalued attributes by haukex
in thread net::ldap ->singel valued attributes and multivalued attributes by docsnyder

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.