sschneid has asked for the wisdom of the Perl Monks concerning the following question:
...which works perfectly, and does exactly what I want. My only problem is that the assignment of values to a temporary array (@a) and then testing whether $a[1] exists as a way to tell whether $entry->get_value is returning multiple values or not seems... well, clumsy.# Perform an LDAP query, returning results in a hash. sub fetch { my $self = shift; %{$self->{'ARG'}} = @_; my ($r); my $result = $self->{'LDAP'}->search( base => $self->{'ARG'}->{'source'}, filter => $self->{'ARG'}->{'filter'} ); foreach my $entry ($result->all_entries()) { map { push my @a, $entry->get_value($_); if ($a[1]) { $r->{$entry->dn()}->{$_} = [ $entry->get_value($_) ]; } else { $r->{$entry->dn()}->{$_} = $entry->get_value($_); } } $entry->attributes(); } return $r; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning single or multiple values?
by ccn (Vicar) on Aug 27, 2004 at 19:27 UTC | |
by sschneid (Deacon) on Aug 27, 2004 at 19:33 UTC | |
|
Re: Returning single or multiple values?
by Arunbear (Prior) on Aug 27, 2004 at 19:25 UTC | |
|
Re: Returning single or multiple values?
by bronto (Priest) on Aug 30, 2004 at 11:10 UTC |