Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I cannot list multiple values for the same attribute

36 views
Skip to first unread message

Mehmet

unread,
Aug 11, 2011, 11:54:03 AM8/11/11
to perl...@perl.org
Hi everyone,

I am new to perl-ldap and like it very much, however I have a problem I
cannot solve by myself (or using google).

I have some attributes with multiple values in the same entry, such as:

description: abc
description: def
description: ghi
...

I perform a search using a base & filter, then try to list all attributes
and their values in a foreach loop:

foreach my $entry ($searchResults->entries) {
foreach my $attr ($entry->attributes) {
for ($attr) { if (/^description$/) { printf ("%s -> %s \n",
$attr, $entry->get_value($attr) ); }
}
}

the reason I am using for ($attr) is that I have several checks in the loop,
which I omit here for readability.

Now the problem: I noticed that $entry->attributes lists each attribute only
once! Therefore, I can only print a single value, which happens to be on the
top of the list (only "abc" in the above example).

Is there any other way to accomplish what I am trying to do? any help will
be greatly appreciate since I am stuck at this point :(

Thanks so much!
-Mehmet

Peter Karman

unread,
Aug 11, 2011, 12:42:52 PM8/11/11
to Mehmet, perl...@perl.org
Mehmet wrote on 08/11/2011 10:54 AM:
> Hi everyone,
>
> I am new to perl-ldap and like it very much, however I have a problem I
> cannot solve by myself (or using google).
>
> I have some attributes with multiple values in the same entry, such as:
>
> description: abc
> description: def
> description: ghi
> ...
>
> I perform a search using a base & filter, then try to list all attributes
> and their values in a foreach loop:
>
> foreach my $entry ($searchResults->entries) {
> foreach my $attr ($entry->attributes) {
> for ($attr) { if (/^description$/) { printf ("%s -> %s \n",
> $attr, $entry->get_value($attr) ); }
> }
> }
>
> the reason I am using for ($attr) is that I have several checks in the loop,
> which I omit here for readability.
>
> Now the problem: I noticed that $entry->attributes lists each attribute only
> once! Therefore, I can only print a single value, which happens to be on the
> top of the list (only "abc" in the above example).
>

You probably want instead something like:

for my $entry ($searchResults->entries) {
for my $attr ($entry->attributes) {
if ($attr eq 'description') {
printf("%s -> %s\n", $attr,
join(", ", $entry->get_value($attr))
);
}
}
}


--
Peter Karman . http://peknet.com/ . pe...@peknet.com

Mehmet

unread,
Aug 11, 2011, 1:04:48 PM8/11/11
to Peter Karman, perl...@perl.org
Peter,

Thanks so much for your super-fast reply, which made me realize that
entry->get_value($attr)
returns a list which can be iterated :)

This definitely did the trick.

-Mehmet

--
=========================================
Mehmet Belgin, Ph.D. (mehmet...@oit.gatech.edu)
Scientific Computing Consultant | OIT - Academic and Research Technologies
Georgia Institute of Technology
258 Fourth Street, Rich Building, Room 326
Atlanta, GA 30332-0700
Office: (404) 385-0665

0 new messages