From: Jim H. <ha...@us...> - 2002-08-15 20:29:46
|
Sean, Use 'get_value' instead of 'get' in my $QUERYLASTNAME = $QUERYRESULTENTRY->get( 'sn' ); get always returns an array, get_value returns the first value if it is in scalar contex, else an array. Don't forget that attributes as well as entries can be milti-valued. --Jim On Thu, 15 Aug 2002, Sean wrote: > > > Hello. > > I have a problem with a script I'm using to query an ldap server. Unfortunately I have to have this script done by tonight so I'm a but > rushed and need some help. > > > The script should always bring back only one entry, but I will be checking that anyway. Once it comes back I want to pull out 4 attributes and set variables to the contents of those attributes for future work. > > When I run the script it shows that one record is returned. However I'm not getting the contents of the attribute correctly. > > Here's the script: > > #!/usr/local/bin/perl > > use CGI; > use Net::LDAP qw(:all); # Use the perl-ldap module > > # Query ldap server for student information > > $ldap = Net::LDAP->new('148.8.60.60') or die "$@"; > $ldap->bind; # Connect anonymous to server > $attrs = ['EmployeeID','userBirthDate','sn','uid' ]; > > my $QUERYRESULT = $ldap->search ( > base => "o=stuorg", > scope => "sub", > filter => "uid=appletor", > attrs => $attrs > ); > > my $QUERYCOUNT = $QUERYRESULT->count; > print $QUERYCOUNT; > > # Verify only one record returned > > if ($QUERYCOUNT eq "0") { > print "query returned no records"; > exit (0); > } > > > # Set query result to first record in array. > my $QUERYRESULTENTRY = $QUERYRESULT->entry(0); > > > # PUll information from ldap record and populate local variables > my $QUERYLASTNAME = $QUERYRESULTENTRY->get( 'sn' ); > print $QUERYLASTNAME; > > > > > The results are: > > > hawk:/tmp # ./test.pl > 1ARRAY(0x2f5c80) > > Thanks! > > > Sean O'Brien > Sr. Unix Engineer > AE Business Solutions |