Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Net::LDAP doesn't return until end of loop

by ypcat (Beadle)
on Jun 30, 2003 at 22:01 UTC ( [id://270340]=note: print w/replies, xml ) Need Help??


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

I changed my callback to be without the shifting of entry. What happens is all looped data including the 10th mac address return "No entry passed...", however the 10th also returns the values from ldap that were queried for. This doesn't make any sense because its acting like for the first 9 Mac's no entry is passed, this I believe, but then on the 10th, no entry is passed, but data is returned ?!? Please advise.
  • Comment on Re: Re: Net::LDAP doesn't return until end of loop

Replies are listed 'Best First'.
Different Strategy (Was: Net::LDAP doesn't return until end of loop)
by lachoy (Parson) on Jul 01, 2003 at 01:48 UTC

    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

      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

      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://270340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-25 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found