[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-ldap-dev
Subject:    Re: ldap-perl query help.  URGENT!
From:       Bob.Goolsby () kp ! org
Date:       2002-08-15 21:35:49
[Download RAW message or body]

This is a multipart message in MIME format.
--=_alternative 00770BD388256C16_=
Content-Type: text/plain; charset="US-ASCII"

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

--=_alternative 00770BD388256C16_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">The quick answer is to dereference the
value returned from your get &nbsp;--</font>
<br>
<br><font size=3># PUll information from ldap record and populate local
variables</font>
<br><font size=3>my $ref = $QUERYRESULTENTRY-&gt;get( 'sn' );</font>
<br><font size=3>my $QUERYLASTNAME = $$ref[0];<br>
print $QUERYLASTNAME;</font>
<br>
<br><font size=2 face="sans-serif">The longer answer is to use get_vaue()
--</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; $QUERYLASTNAME
= $QUERYRESULTENTRY -&gt; get_value(&quot;sn&quot;); &nbsp;It does the
dereference for you if you call it in scalar context.</font>
<br>
<br>
<br><font size=2 face="sans-serif">B</font>
<br><font size=2 face="sans-serif"><br>
<br>
Bob Goolsby<br>
bob.goolsby@kp.org<br>
(925) 926-3406</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=37%><font size=1 face="sans-serif"><b>&quot;Sean&quot; &lt;mbuna@badgerstate.com&gt;</b></font>
<br><font size=1 face="sans-serif">Sent by: perl-ldap-dev-admin@lists.sourceforge.net</font>
<p><font size=1 face="sans-serif">08/15/2002 01:10 PM</font>
<td width=62%>
<table width=100%>
<tr valign=top>
<td width=9%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=90%><font size=1 face="sans-serif">&lt;perl-ldap-dev@lists.sourceforge.net&gt;</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">bcc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">ldap-perl query help. &nbsp;URGENT!</font></table>
<br></table>
<br>
<br>
<br><font size=3>&nbsp;</font>
<br><font size=3>&nbsp;</font>
<br><font size=3>Hello.<br>
<br>
I have a problem with a script I'm using to query an ldap server. &nbsp;Unfortunately
I have to have this script done by tonight so I'm a but<br>
rushed and need some help.<br>
<br>
<br>
The script should always bring back only one entry, but I will be checking
that anyway. &nbsp;Once it comes back I want to pull out 4 attributes and
set variables to the contents of those attributes for future work.<br>
<br>
When I run the script it shows that one record is returned. However I'm
not getting the contents of the attribute correctly.<br>
<br>
Here's the script:<br>
<br>
#!/usr/local/bin/perl<br>
<br>
use CGI;<br>
use Net::LDAP qw(:all); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;# Use the perl-ldap module<br>
<br>
# Query ldap server for student information<br>
<br>
$ldap = Net::LDAP-&gt;new('148.8.60.60') or die &quot;$@&quot;;<br>
$ldap-&gt;bind; &nbsp; &nbsp; &nbsp; &nbsp; # Connect anonymous to server<br>
$attrs = ['EmployeeID','userBirthDate','sn','uid' ];<br>
<br>
my $QUERYRESULT = $ldap-&gt;search (<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;base &nbsp; &nbsp;=&gt;
&quot;o=stuorg&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scope &nbsp; =&gt;
&quot;sub&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filter &nbsp;=&gt;
&quot;uid=appletor&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;attrs &nbsp; =&gt;
&nbsp;$attrs<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);<br>
<br>
my $QUERYCOUNT = $QUERYRESULT-&gt;count;<br>
print $QUERYCOUNT;<br>
<br>
# Verify only one record returned<br>
<br>
if ($QUERYCOUNT eq &quot;0&quot;) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print &quot;query returned no records&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;exit (0);<br>
 &nbsp; &nbsp;}<br>
<br>
<br>
# Set query result to first record in array.<br>
my $QUERYRESULTENTRY = $QUERYRESULT-&gt;entry(0);<br>
<br>
<br>
# PUll information from ldap record and populate local variables<br>
my $QUERYLASTNAME = $QUERYRESULTENTRY-&gt;get( 'sn' );<br>
print $QUERYLASTNAME;<br>
<br>
<br>
<br>
<br>
The results are:<br>
<br>
<br>
hawk:/tmp # ./test.pl<br>
1ARRAY(0x2f5c80)</font>
<br><font size=2 face="Arial">Thanks!</font>
<br><font size=3>&nbsp;</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 face="Arial">Sean O'Brien<br>
Sr. Unix Engineer<br>
AE Business Solutions</font>
<br>
--=_alternative 00770BD388256C16_=--


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic