You should verify that your bind call goes right. For example with

use Net::LDAP::Util qw(ldap_error_text ldap_error_name) ; my $msg ; # you will need it several times $msg = $ldap->bind(%your_bind_params) ; if ($msg->is_error) { my $code = $msg->code ; die join "\n",ldap_error_name($code), ldap_error_text($code) ; }

you will get an idea of what goes wrong.

Next, it seems you don't cycle over the %petra hash, your $dn doesn't depend on the username... how could you get it to put all your users into the directory server?

To put the users in, I'd use something like this untested code, based on yours:

while (my ($username,$userdata) = each %petra) { my $entry = Net::LDAP::Entry->new(); my $dn = calculate_it_using($username) ; $entry->dn($dn) ; $entry->changetype("add"); $entry->add(@$userdata) ; $msg = $entry->update($ldap) ; if ($msg->is_error) { # die() the same way as before. I'd suggest # to create a subroutine to do the job, e.g. # die_ldap_error($msg->code) } }

I seldom use that syntax anyway. I prefer using $ldap->add($entry) instead. But that's a matter of taste :-)

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->make($love) ;
}


In reply to Re: perl-LDAP process hangs by bronto
in thread perl-LDAP process hangs by Notromda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.