On 14/8/02 7:23 am, Craig Robinson <cra...@ep...> wrote:
> Net::LDAP experts,
>
> I have a problem that has been bugging me for ages.
>
> I am trying to see if an email address exists within our organization. The
> following is a snippet of code which returns the DN of an entry which matches
> a certain email address:
>
> use Net::LDAP;
> $ldap = Net::LDAP->new("bartfarst.env.qld.gov.au") or die "$@";
> $DS_mesg = $ldap->search(base => "o=env,st=qld,c=au",filter =>
> "mail=craig.robinson\@epa.qld.gov.au");
> $DS_entry = $DS_mesg->shift_entry;
> $DS_dn = $DS_entry->dn;
> print "DN: $DS_dn\n";
> $ldap->unbind;
>
> It works great if the email address exists. BUT if the email address does not
> exist, I get the following error message:
>
> "Can't call method "dn" on an undefined value at test.pl line 5."
>
> I would prefer a message like:
>
> "Sorry Craig, there is no entry which has this email address"
>
> Does anyone know of a <simple> way of finding out if an entry containing a
> specific attribute exists, or better still, DOES NOT EXIST??
This is not entirely what you've asked for, but it solves the problem for
the above scriptlet.
$DS_mesg = $ldap->search(...);
if ($DS_mesg->count() != 1) {
print "Cannot find one entry with this email address\n";
} else {
$DS_entry = $DS_mesg->shift_entry;
...
}
Cheers,
Chris
|