From: Craig R. <cra...@ep...> - 2002-08-15 03:17:26
|
I knew this list would come up with the goods. Thanks to Chris Ridd and Ji= m Harle for their feedback. Here's the response from Chris: ----- >% snip ------ This is not entirely what you've asked for, but it solves the problem for the above scriptlet. $DS_mesg =3D $ldap->search(...); if ($DS_mesg->count() !=3D 1) { print "Cannot find one entry with this email address\n"; } else { $DS_entry =3D $DS_mesg->shift_entry; ... } ----- >% unsnip ------ Here's the response from Jim: ----- >% snip ------ Your statement $DS_entry =3D $DS_mesg->shift_entry; makes the assumption that one or more objects matched your filter. There a= re several approaches to this: $DS_entry =3D $DS_mesg->shift_entry; if (defined $DS_entry) { $DS_dn =3D $DS_entry->dn; print "DN: $DS_dn\n"; } else { print "Sorry\n"} or foreach $DS_entry ($DS_mesg->all_entries) { $DS_dn =3D $DS_entry->dn; print "DN: $DS_dn\n"; } ----- >% unsnip ------ In the end, here is my revised bit of code which does exactly what I'm afte= r: use Net::LDAP; $ldap =3D Net::LDAP->new("test.env.qld.gov.au") or die "$@"; $DS_mesg =3D $ldap->search(base =3D> "o=3Denv,st=3Dqld,c=3Dau",filter =3D> = "mail=3Dcraig.robinson\@epa.qld.gov.au"); if ($DS_mesg->count() !=3D 1) { print "Cannot find one entry with this email address\n"; } else { $DS_entry =3D $DS_mesg->shift_entry; $DS_dn =3D $DS_entry->dn; print "DN: $DS_dn\n"; } $ldap->unbind; Hope this helps some others also. Cheers, Craig Craig Robinson Environmental Protection Agency Tel: (07) 3006 4629 Fax: (07) 3247 6534 Email: cra...@ep... Visit us at: http://www.epa.qld.gov.au |