Newsgroups: perl.ldap Path: g2news2.google.com!news1.google.com!news.glorb.com!usenet.stanford.edu!nntp.perl.org Return-Path: Mailing-List: contact perl-ldap-h...@perl.org; run by ezmlm Delivered-To: mailing list perl-l...@perl.org Received: (qmail 32711 invoked from network); 11 Aug 2011 17:05:26 -0000 Received: from x1.develooper.com (207.171.7.70) by x6.develooper.com with SMTP; 11 Aug 2011 17:05:26 -0000 Received: (qmail 30383 invoked by uid 225); 11 Aug 2011 17:05:26 -0000 Delivered-To: perl-l...@perl.org Received: (qmail 30379 invoked by alias); 11 Aug 2011 17:05:25 -0000 X-Spam-Status: No, hits=-0.8 required=8.0 tests=DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: la.mx.develooper.com Received: from mail-ww0-f45.google.com (HELO mail-ww0-f45.google.com) (74.125.82.45) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Thu, 11 Aug 2011 10:05:23 -0700 Received: by wwg9 with SMTP id 9so1283816wwg.26 for ; Thu, 11 Aug 2011 10:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=NdjRn81uzghYzZ3R7PrAX6ZQcM82SqxuI0gcTn42ayE=; b=VRiOObZ+TYE1t+qh/ogsxzdKHzPOAdlk473qINnrxgzVoV9lkjA/QS1lToQHGULoEI GFzAh3V4cRnwBNJBoFuxVeV2HptsTZWJriG0Aj6e2as39rh4/GGB8W3ztt16c9HhOClX cNsCmd0Ew7G0b8bfiS8lKdLu0DirppQIYei6s= Received: by 10.216.133.197 with SMTP id q47mr1914956wei.90.1313082318114; Thu, 11 Aug 2011 10:05:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.172.7 with HTTP; Thu, 11 Aug 2011 10:04:48 -0700 (PDT) In-Reply-To: <4E44068C.8030807@peknet.com> References: <4E44068C.8030807@peknet.com> Date: Thu, 11 Aug 2011 13:04:48 -0400 Message-ID: Subject: Re: [Net::LDAP] I cannot list multiple values for the same attribute To: Peter Karman Cc: "perl-l...@perl.org" Content-Type: multipart/alternative; boundary=00504502e1b321d18c04aa3dcd95 X-Virus-Checked: Checked Approved: n...@nntp.perl.org From: mbel...@gmail.com (Mehmet) --00504502e1b321d18c04aa3dcd95 Content-Type: text/plain; charset=ISO-8859-1 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 On Thu, Aug 11, 2011 at 12:42 PM, Peter Karman wrote: > 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 Belgin, Ph.D. (mehmet.bel...@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 --00504502e1b321d18c04aa3dcd95--