The quick answer is to dereference the value returned from your get  --

# PUll information from ldap record and populate local variables
my $ref = $QUERYRESULTENTRY->get( 'sn' );
my $QUERYLASTNAME = $$ref[0];
print $QUERYLASTNAME;


The longer answer is to use get_vaue() --

        $QUERYLASTNAME = $QUERYRESULTENTRY -> get_value("sn");  It does the dereference for you if you call it in scalar context.


B


Bob Goolsby
bob.goolsby@kp.org
(925) 926-3406



"Sean" <mbuna@badgerstate.com>
Sent by: perl-ldap-dev-admin@lists.sourceforge.net

08/15/2002 01:10 PM

To
<perl-ldap-dev@lists.sourceforge.net>
cc
bcc
Subject
ldap-perl query help.  URGENT!




 
 
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