On 13/10/06 6:57, Chris Ridd <[EMAIL PROTECTED]> wrote: > On 13/10/06 11:43, Y-Man <[EMAIL PROTECTED]> wrote: > >> Hi >> >> I'm attempting to search through a ldap entry and display all it's >> attributes. Some of the attributes may have the same name but the code >> that I'm using does only displays one of them. >> >> >> $mesg = $ldap->search(filter=>"(uid=xyz)", base=>$base); >> @entries = $mesg->entries; >> >> foreach $entry (@entries) { >> >> foreach $attr ($entry->attributes) { >> print $attr." - ".$entry->get_value($attr)."\n"; >> } >> } >> >> Can anyone tell me what I'm doing wrong? >> > > If called in a scalar context, get_value only returns one of the attribute's > values. Call it in a list context instead, so you have three nested loops: > > foreach $entry (@entries) { > foreach $attr ($entry->attributes) { > foreach $val (@{$entry->get_value($attr)}) { > print "$attr - $val\n"; > } > } > } > > As I'm only testing in my mail client, I can't be sure if you absolutely > need the @{ and } around the call to get_value. But it forces list context, > so ought to work.
As Graham has just pointed out, that's wrong. I was possibly thinking of array refs. The innermost loop should just be: foreach $val ($entry->get_value($attr)) { print "$attr - $val\n"; } Cheers, Chris