Hi all, Just started using perl-ldap (long time perldap user). The examples in the docs generally deal with processing multiple entries returned by a search, using various loops and such. What if I know a search will only return a single entry (search keyed on unique attribute)?
What I am looking for is examples of referencing the various
hashes/arrays returned in the search without looping through $entries,
$attrs etc.
I just did something like this but it looks real ugly to me (NOTE: I
am a long time perl and perldap user, but not an expert, especially
when dealing with references):
#!/usr/bin/perl -w
# Creates a series of NIS+ accounts based on data int LDAP
use Net::LDAP;
$ldap = Net::LDAP->new("foo.com") or die "$@";
open(ACCTS,"accts.txt") or die "$@";
$mesg = $ldap->bind(blah,blah,version=>3);
while (<ACCTS>) {
$result = $ldap->search (
base => "o=foo",
scope => "one",
filter => "uid=$_",
attrs =>
['uid','uidnumber','gidnumber','userpassword',
'gecos','homedirectory','loginshell']
);
next unless defined($result->entry(0));
$entry = $result->entry(0);
#
# This bit seems real ugly to me!
#
$uid = $entry->get_value('uid',asref=>1);
$userpassword = $entry->get_value('userpassword',asref=>1);
$$userpassword[0] =~ s/{crypt}//;
$uidnumber = $entry->get_value('uidnumber',asref=>1);
$gidnumber = $entry->get_value('gidnumber',asref=>1);
$gecos = $entry->get_value('gecos',asref=>1);
$homedirectory = $entry->get_value('homedirectory',asref=>1);
$loginshell = $entry->get_value('loginshell',asref=>1);
print "/usr/bin/nistbladm -a ",
"name=$$uid[0] passwd=$$userpassword[0] ",
"uid=$$uidnumber[0] gid=$$gidnumber[0] ",
"gcos=\"$$gecos[0]\" home=$$homedirectory[0] ",
"shell=$$loginshell[0] passwd.org_dir.foo.com.\n";
}
--
Mark E. Drummond <[EMAIL PROTECTED]> http://www.klug.on.ca
icq: 19153754 jabber: [EMAIL PROTECTED] pgp: 0x095F6183
F834 7A42 2E68 3FA2 A1BD 27BF 163D 892C 095F 6183
pgp00000.pgp
Description: PGP signature
