Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Different Strategy (Was: Net::LDAP doesn't return until end of loop)

by lachoy (Parson)
on Jul 01, 2003 at 01:48 UTC ( [id://270382]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Net::LDAP doesn't return until end of loop
in thread Net::LDAP doesn't return until end of loop

Two things: First, you probably want to pass \@attrs or [ @attrs ] instead of what you've got. You might also need to set scope => 'sub' in the search attributes.

Second, I'd try a different strategy, using this idiom to run through the results of a search:

my $ldap_msg = $ldap->search( ... ); if ( my $code = $ldap_msg->code ) { die "Error running search: ", Net::LDAP::Util::ldap_error_text( $code ); } while ( my $entry = $ldap_msg->shift_entry ) { # use $entry }

It's been a while since I used LDAP and I just cribbed this from SPOPS::LDAP, which I wrote when I was using LDAP :-)

Chris
M-x auto-bs-mode

Replies are listed 'Best First'.
Re: Different Strategy (Was: Net::LDAP doesn't return until end of loop)
by ypcat (Beadle) on Jul 01, 2003 at 05:07 UTC
    I re-did the code to match you're strategy, cause I am not against changing what I am doing. This is my first time with Perl/LDAP and it is a time pressed issue so I really appreciate all you're help and guidance. After re-writing the code it is still experiencing the same issue. Here is the new code.
    sub ldapsearch { my $mac = shift; print "$mac\n"; my $searchobj = $connection->search( base => 'o=ldap', scope => 'sub', filter => "cn=$mac", attrs => @attrs, #note I al +so tried \@attrs ); $searchobj->code && die $searchobj->error; while ( my $entry = $searchobj->shift_entry) { print $entry->dn, "\n"; print $entry->get_value('plan'); print $entry->get_value('ipaddress'); print $entry->get_value('username'); } }


    Any suggestion ?

      Sorry, but the only thing I could suggest at this point is create your LDAP connection with 'debug => 12' or such (see Net::LDAP docs under new() for what this means). Good luck.

      Oh, and one more thing: it's definitely \@attrs

      Chris
      M-x auto-bs-mode

Re: Different Strategy (Was: Net::LDAP doesn't return until end of loop)
by ypcat (Beadle) on Sep 17, 2003 at 06:26 UTC
    Well,

    After reviewing this thread for the 100th time I figured out what my issue was. In the first reply archon states your not comping your $mac, boy was he ever right. This was fixed by throwing a chomp $mac into my for each loop before the sub routine ldapsearch() is called. Thanks again for everyones help. Atleast now my code is a little more refined and works !

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://270382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-19 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found