I have reverted to the previous code, as I am getting no where with this exploration. This code gives me the DN from ou3 file to the OUT file, but once I hit the $entry = $dn->pop_entry(): line, it breaks again. If I do not use the pop_entry() method, each result sends the following to OUT (Net::LDAP::Search=HASH(0x1c72f1c)). Is there any other way around this problem? Thanks again.

#! perl use strict; use warnings; use diagnostics; use Net::LDAP; use Net::LDAP::Entry; use Net::LDAP::Search; use Net::LDAP::LDIF; open PERSON, "<", "ou3" or die "Cannot open 'ou3': $!"; open MGR, "<", "ou8" or die "Cannot open 'ou8': $!"; open OUT, ">", "buildAD.ldif" or die "Cannot open 'buildAD.ldif': $!"; my $HOST = "11"; my $ADMIN = "cn=d"; my $PWD = "0"; my $BASEDN = "DC=corp"; my $ldap = Net::LDAP->new("$HOST", port=>389) or die "$@"; my $dn = $ldap->bind("$ADMIN", password=>"$PWD"); my @attr = "1.1"; my $result = Net::LDAP::LDIF->new( "buildAD.ldif", "a", wrap=>40 ); my $entry = <>; while (<PERSON>){ chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr], ); next unless $dn; #make sure something is returned $entry = $dn->pop_entry(); $result->write_entry($entry); print OUT "changetype: modify"; print OUT "replace: manager"; } $dn = $ldap->unbind; #session ends close OUT or die "Cannot close in-memory file: $!"; close MGR or die "Cannot close in-memory file: $!"; close PERSON or die "Cannot close in-memory file: $!";

In reply to Re^6: Perl Builds an LDIF by rfransix
in thread Perl Builds an LDIF by rfransix

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.