I have the following code (a helper sub for Net::LDAP):
# 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;
}
...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.
Is there a better way?